我的表格具有id
email_form
和空白操作:
<form id="email_form" action="" method="post" enctype="text/plain" onsubmit="set_form_action()">
这是函数set_form_action()
的定义:
function set_form_action() {
document.getElementById("email_form").action =
'mailto:helloworld@helloworld.com' +
'?subject=Test email&body=Thank you for your order.' +
' Please see below for your order details.' +
'%0D%0A%0D%0A----------------------%0D%0A' +
'Name: ' + document.getElementById("name").value + '%0D%0A' +
'Date: ' + document.getElementById("date").value + '%0D%0A' +
// etc...
}
结果是不可预测的。在Linux Firefox上,一切正常。身体正确填充,"到:"字段也正确设置为helloworld@helloworld.com
。
但是,在Linux Chrome上运行相同的HTML页面," TO:"字段设置为///helloworld@helloworld.com
。另外,此页面在Windows Firefox或Chrome,Body和TO上完全不起作用:字段都是完全空的。
如何定义mailto
函数,什么决定了如何解析数据并将其发送给电子邮件客户端?
刚刚测试了以下代码:
<form name="email_form" action="" method="post" enctype="text/plain">
</form>
<button onclick="set_form_action()">Set Form Action</button>
<script>
function set_form_action() {
document.email_form.action =
'mailto:helloworld@helloworld.com';
alert(document.email_form.action);
}
</script>
并且在以下浏览器中正常工作:
- 最新的Firefox版本58.0.2
- 最新的Google Chrome版本64.0.3282.186(官方构建((64位(
- Internet Explorer版本11.0.9600.18920
- Safari版本11.0.3
我没有Linux,所以不能在那里进行测试。我真的看不到你为什么遇到问题。但我希望这有助于使您指向正确的方向。