Sending html email having JQuery scripts

20,785

Solution 1

Most email clients either disable email JavaScript entirely, or only allow a subset of it, due to security reasons. Web-based clients such as Gmail are likely to fall into the former category.

You can try embedding the script file itself directly into the email, but overall using JS in emails is a bad idea that's best avoided.

edit

Remember, email is a static content-delivery mechanism. As another commentator noted, if you want to send someone dynamic content, email them a link to your DHTML webpage.

Solution 2

@Karim79, I'm not convinced that the answer is so clear cut as you suggest.

It all depends on the environment used to read the email, and whether that environemnt supports javascript or not. Admittedly, I suspect that most email readers would be averse to supporting javascript, in order to avoid viruses and malware, but there is no absolute reason why this couldn't be done.

Having said that, the unpredictable level of support offered by readers would probably mean that you shouldn't rely on the script running correctly (if at all), so you'd probably want to take a 'graceful degradation' approach.

Share:
20,785
Brad
Author by

Brad

Updated on July 09, 2022

Comments

  • Brad
    Brad almost 2 years

    I'm using PHP to send html emails. I've tried to import css files inside the email, and it works fine.

    <link href="http://www.mywebsite.com/css/mail_styles.css" 
          type="text/css" rel="stylesheet" />
    

    But i want the email to look stylish with some JQuery tricks, so i tried to import the JQuery library inside the email to add some scripts, but even gmail couldn't read the library.

    <script type="text/javascript" 
            src="http://www.mywebsite.com/scripts/jquery.js"></script>
    

    So is there a way to import JavaScript libraries inside html emails ?

    Thanks ...

  • karim79
    karim79 over 14 years
    @belugabob - I agree, it's not a clear cut but I like to pretend it is :) Removed my answer as there are better (real) ones here, like this one. Voted up.
  • Brad
    Brad over 14 years
    Thanks everyone ... Then, it's better not to use JavaScript in emails. I will create a static e-mail with my content without script styling + write the link of a corresponding link to a similar DHTML webpage that is having all the script styles i want. Now user can select which one to use.