0

The 'click' event in not trigger when you click on a link in gmail. Click on links in other sites work and clicking on simple text in gmail works. But not when you click on a link in gmail.

$('body').on('click', function(event) {
    console.log("Entered function");
});

Also tried the following, but no luck.

$('a').click(function(){
    console.log("Entered function");
});
jason
  • 3,471
  • 6
  • 30
  • 43
  • What "other sites" specifically? – Luke Shaheen Apr 07 '13 at 22:33
  • "I'm afraid such functionality, while theoretically possible, wouldn't be very practical given that most email clients strip out or disable JavaScript in order to prevent malicious code execution or other security issues" http://stackoverflow.com/questions/2520300/how-to-embed-functionality-into-html-email – Luke Shaheen Apr 07 '13 at 22:36
  • For one example of another site: reddit.com works and triggers the event. – jason Apr 07 '13 at 22:36
  • @John This is not about email clients, just email in a web browser. Does this still hold true? – jason Apr 07 '13 at 22:40
  • Reddit != gmail so the comparison is apples to oranges. John's comment is correct. – j08691 Apr 07 '13 at 22:42
  • can you provide a link of a sample email that we can check in a browser? – trajce Apr 07 '13 at 22:44
  • @j08691 John says that email clients strip out javascript. Agreed. I am seeing reddit the website triggers click on links. Web based Gmail is also triggering clicks everywhere (so javascript is active), but only when clicking on links it doesn't work. So John's comment while may be correct, I am afraid I am not able to see the connection to the issue I am having. – jason Apr 07 '13 at 22:46
  • @trajce I can give you a link, but it works as a web page, only when opened inside gmail, this happens. So just look for any email in your gmail (eg.pintrest, groupon, travelocity etc) and try to click an outbound link. – jason Apr 07 '13 at 22:53
  • 1
    @jason Drop jQuery and bind the event using JavaScript's [addEventListener](https://developer.mozilla.org/en-US/docs/DOM/EventTarget.addEventListener) with capture=true. – Rob W Apr 08 '13 at 10:30
  • @RobW thanks, I will try that and post back. – jason Apr 09 '13 at 06:27

1 Answers1

1

In most email clients i've tried javascript in, it doesn't work. As john pointed out, the answers to this post points out why it is usually disabled;

I'm afraid such functionality, while theoretically possible, wouldn't be very practical given that most email clients strip out or disable JavaScript in order to prevent malicious code execution or other security issues

I guess you could use it if you know your audience very well, since, as the first answer to this post (written in 2010 so don't get your hopes up too much)

Lotus Notes, Mozilla Thunderbird, Outlook Express, and Windows Live Mail all seem to support some sort of JavaScript execution. Nothing else does.

A last resort might be writing a virus that gets into the computer just by opening the email, and then alternating the source code of the email client to enable javascript functionality. I wouldn't recommend that, though.

Use a linked photo instead. please.

Community
  • 1
  • 1