如何在电子邮件中运行JavaScript或jQuery [英] How to run JavaScript or jQuery in a Email

查看:274
本文介绍了如何在电子邮件中运行JavaScript或jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个要求,我必须发送一封电子邮件,当我点击该按钮时,该电子邮件包含一个按钮,我必须调用java脚本或JQuery函数。这可能吗?

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?

推荐答案

Javascript通常在电子邮件客户端被阻止,只是因为它可以造成损害。即使是基于Web的电子邮件服务也会剥离任何脚本。



有关原因的一个非常简单的示例,请考虑以下情况:

您在开放式办公室打开垃圾邮件,大约十几个同事开始他们的日常工作。

电子邮件使用javascript带你到一个成人视频网站,并开始播放一个随机视频 - 在javascript使你的扬声器响起之后到最大

每当你疯狂地尝试关闭该网站时,javascript会打开另一个网站,每个网页都会比以前更糟糕。

十分钟后,你试图解释对于人力资源而言,这不是你的错,你不应该被指控违反大量的公司规则。

我相信你能得到这张照片。



因此,除非您打算编写自己的电子邮件客户端,并坚持要发送电子邮件的所有人使用它,否则我强烈怀疑您无法做到什么。想。

至少,不是直接。



但是,您可以轻松地在电子邮件中添加超链接 - 您甚至可以应用图形如果您希望它看起来像一个按钮,则链接到该链接 - 并使链接将您带到一个网页,该页面在页面加载时运行您想要的任何脚本 - 或在该页面上放置另一个按钮。
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.


这篇关于如何在电子邮件中运行JavaScript或jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆