Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML email with Javascript [closed]

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

like image 212
moejoe11 Avatar asked Jul 06 '09 16:07

moejoe11


People also ask

How do I enclose JavaScript in HTML?

I.</script> tag of the HTML that wrap around JavaScript code inside the HTML program. Users can also define JavaScript code in the <body> tag (or we can say body section) or <head> tag because it completely depends on the structure of the web page that the users use.

Can you use JavaScript in an HTML email?

With HTML in your email, you can format the text, incorporate images, and do most of the same things in the email that you can do in a web page. As you can incorporate JavaScript into HTML in a web page, you can of course similarly incorporate JavaScript into HTML in an email.

Does JavaScript work in email template?

JavaScript in Email Templates is an absolute NO! Unfortunately, hackers and people looking to steal information also sometimes use JS in emails. Running JavaScript in email templates can create serious security threats. Hence why it makes sense to have email clients blocking them by default.

Does Gmail allow JavaScript?

13, Google will no longer allow JavaScript attachments on its Gmail service, killing one of the main methods of malware distribution over the past two years. Users will no longer be able to attach . JS files to emails in Gmail, regardless of whether they attach them directly or they include them in archives like .


2 Answers

I don't think that is possible in an email, nor should it be. There would be major security ramifications.

like image 69
Bryan Rowe Avatar answered Sep 21 '22 17:09

Bryan Rowe


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.

like image 32
Dana the Sane Avatar answered Sep 21 '22 17:09

Dana the Sane