views:

392

answers:

4

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

+11  A: 

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

Bryan Rowe
+10  A: 

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.

landon9720
+1  A: 

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.

Dana the Sane
Note that you don't have to use <a name="foo"> to put down an anchor for the link - just having an element with the proper id attribute will work. So if you have <a href="#section1">Jump to section!</a>, then later on when that section start you just need something like <h1 id="section1">Section 1</h1>.
Xanthir
Thanks, modified the example to reflect that.
Dana the Sane
+2  A: 

Just as a warning, many modern email browsers have JavaScript disbaled for incoming emails as it can cause security flaws. This means that many of the people you are emailing may not be able to use the content.

PS. Didn't see above post's at time of posting. My bad.

Ryan