Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a requirement where i have to send an email and that email contains a button when i click that button i have to call a java script or JQuery function. Is this possible?
Posted
Comments
Kornfeld Eliyahu Peter 17-Feb-15 3:06am    
Hopefully not...
Mohibur Rashid 17-Feb-15 3:08am    
You better not. That is a bad idea. Your email would be spammed. Most case email client won't run your Javascript. So, please plan something else.
Nitij 17-Feb-15 5:13am    
You seriously want to try that?

1 solution

Javascript is usually blocked in email clients, simply because of the damage that it can do. Even web-based email services tend to strip out any scripts.

For a very simple example of why, consider this scenario:
You open a spam email, in your open-plan office, while about a dozen of your co-workers go about their daily tasks.
The email uses javascript to take you to an adult video website, and starts playing a random video - after the javascript has cranked your speakers up to the max.
Every time you franticly try to close that website, the javascript opens another one, each one worse than the one before.
Ten minutes later, you're trying to explain to human resources that it wasn't your fault, and you shouldn't be charged with breaching a ton of company rules.
I'm sure you get the picture.

So, unless you're planning to write your own email client, and insist that everyone you want to email uses it, I strongly suspect that you're not going to be able to do what you want.
At least, not directly.

However, you could easily put a hyperlink in your email - you could even apply a graphic of a button to that link if you want it to look like a button - and have the link take you to a web page that runs whatever scripts you want on page load - or put another button on that page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900