HTML email with Javascript [closed]

2019-01-01 13:46发布

How to include javascript in HTML emails - We need it for expanding and collapsing of the content in the HTML email.

8条回答
倾城一夜雪
2楼-- · 2019-01-01 14:11

Do not depend on this. Any good mail client will not support executable code within an email. Any knowledgeable user will not use a client that does.

查看更多
弹指情弦暗扣
3楼-- · 2019-01-01 14:13

The short answer is that scripting is unsupported in emails.

This is hardly surprising, given the obvious security risks involved with a script running inside an application that has all that personal information stored in it.

Webmail clients are mostly running the interface in JavaScript and are not keen on your email interfering with that, and desktop client filters often consider JavaScript to be an indicator of spam or phishing emails. Even in the cases where it might run, there really is little benefit to scripting in emails.

Keep your emails as straight HTML and CSS, and avoid the hassle. Here is what you can do in html emails: https://www.campaignmonitor.com/guides/coding/technologies/

查看更多
浅入江南
4楼-- · 2019-01-01 14:14

What you are trying to achieve should be done in the web browser because javascript simply doesn't work with html email design. The various email clients that are out there e.g. gmail, outlook, yahoo strip scripts put of the code for security reasons.

It is best to just use HTML and CSS to style your emails. Maybe you could have a call to action (cta) in your html email that sends the user to a web page with your expanding and collapsing content feature.

查看更多
余欢
5楼-- · 2019-01-01 14:18

you can use html radio/checkbox input with labels and css to achieve the expanding effects you want.

查看更多
ら面具成の殇う
6楼-- · 2019-01-01 14:19

Agree completely with Bryan and others.

Instead, consider using multiple sections in your email that you can jump to using links and anchors (the 'a' tag). I think that you can emulate the behavior you want by including multiple copies of the text further down in your email. This is a bet messy though, so you could just have sets of anchors that link to each other and allow you to move back in forth between the 'summary' section and the 'expanded' one.

Example:

<a href="#section1">Jump to section!</a>
<p>A bunch of content</p>
<h2 id="section1">An anchor!</h2>

Clicking on the first link will move focus to the sub-section.

查看更多
泛滥B
7楼-- · 2019-01-01 14:20

Here's what you CAN do:

You can attach (to the email) an html document that contains javascript.

Then, when the recipient opens the attachment, their web browser will facilitate the dynamic features you've implemented.

查看更多
登录 后发表回答