javascript - Button is not executing javascript in Email
问题描述
I am sending an email in go which contains html template as it's email content. The html file has a table and a button at the bottom. I have written a script code to handle the click of the button in the email but the script tag seems not being called after the button click. Hence nothing is happening.
This is my html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
Hello,
</td>
</tr>
<tr>
<td>
You have been assigned a task. Please click on the button below.
</td>
</tr>
<tr>
<td>
<button type="button" id="button">Click me</button>
</td>
</tr>
</table>
<script type="application/javascript">
document.getElementById("button").onclick = function() {
//perform actions on button click
};
</script>
</body>
</html>
These are the header that I am using for sending the email:
header["MIME-Version"] = "1.0"
header["Content-Type"] = ""text/html"; charset=\"utf-8\""
The email is sent and being rendered successfully but the click of the button does nothing. Any help will be highly appreciated.
解决方案
电子邮件不允许在 HTML 中使用 JavaScript。
电子邮件提供商通常会去除 html 模板中的 javascript 内容,以确保后台没有运行可能危及用户数据的恶意脚本。
我建议使用<a>
(锚标记)指向链接,而不是使用电子邮件中的按钮。
推荐阅读
- php - PHP从项目列表创建数组
- javascript - Laravel:如何在创建后停留在页面上再创建一个项目
- amazon-web-services - 在 AWS 中创建具有多个值的标签
- python - 使用 Python3 抓取雅虎财经
- spring - 自动装配 Bean 的 Spring 配置文件
- java - 在选择处于活动状态时添加/删除时线程“AWT-EventQueue-0”java.lang.NullPointerException 中的异常
- delphi - 我可以使用 Delphi 10.3 或 10.4 Professional 通过 FireDAC 连接到远程 Firebird 数据库吗?
- javascript - 如何将多个下拉值和普通文本添加到 texbox
- data-structures - 从优先级队列中删除没有最高优先级的节点
- arrays - 为什么将数组定义移动到另一个类中会将其项类型更改为复杂对象?