单击IE8/Chrome之后打开Mailto
-
21-09-2019 - |
题
我目前正在尝试执行以下操作:
触发器:单击选择列表中的名称。
操作:在当前窗口中打开邮件链接,从而打开电子邮件客户端。
$(document).ready(function(){
// Define click-event
$('option').click(function(){
var mail = $(this).attr('value');
window.open('mailto:'+mail, '_self');
});
});
我还尝试使用此而不是window.open:
parent.location.href= 'mailto:'+mail;
但是,两者仅在Firefox中起作用,在IE8或Chrome中没有错误/结果。
有人知道问题可能是什么?
解决方案
怎么样(在IE8上对我有用)
$('option').change(function() {
var target = 'mailto:' + $('option:selected', this).text();
window.location=target;
});
可能有一种更好的方法可以做到这一点,但是我在其中一个页面上使用了类似的东西。
如果可以将电子邮件地址存储为选择选项值,请在末尾使用.val()而不是.text()。
不隶属于 StackOverflow