jQuery的mailto与锚元素 [英] jQuery mailto with anchor element
问题描述
我用网上看到的很多例子试了这个。但我想没有那么简单,适用于所有浏览器(IE 8及以上版本)。
我试图简单地打开带有mailto链接的Outlook窗口。
< a href =#name =emailLinkid =emailLink>电子邮件< / a>
JQuery:
< ('click',function(event){
alert(Huh);
var($ {
$('#emailLink')。 email ='test@theearth.com';
var subject ='Circle Around';
var emailBody ='Some blah';
window.location ='mailto:'+ email +' ?subject ='+ subject +'& body ='+ emailBody;
});
});
当然,我是一个jQuery新手。以上只是不起作用。它只是闪烁浏览器,但没有打开。我猜这是因为 window.location
。
有没有简单的解决方案?我希望这可以在IE8&上面和所有浏览器中。
主体自动生成(在JSP中)。 / b>
这里的工作解决方案:
< a href =#name =emailLinkid = emailLink>电子邮件与LT; / A>
和函数:
($ click),function(event){
event.preventDefault();
($('#emailLink')。 alert(Huh);
var email ='test@theearth.com';
var subject ='Circle Around';
var emailBody ='Some blah';
window.location ='mailto:'+ email +'?subject ='+ subject +'& body ='+ emailBody;
});
});
I tried this with umpteen examples we see on the net. But I guess there is none that is simple and works on all browsers (IE 8 and above as well).
I am trying to simply open up Outlook window with mailto link.
<a href="#" name="emailLink" id="emailLink">Email</a>
JQuery:
$(function () {
$('#emailLink').on('click', function (event) {
alert("Huh");
var email = 'test@theearth.com';
var subject = 'Circle Around';
var emailBody = 'Some blah';
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
});
});
Granted, I am a jQuery newbie. The above just doesn't work. It just flickers the browser but nothing opens. I guess this is because of window.location
.
Is there a simple solution? I want this to work in IE8 & above and in all browsers.
The body is generated automatically (in JSP).
here's working solution:
<a href="#" name="emailLink" id="emailLink">Email</a>
and the function:
$(function () {
$('#emailLink').on('click', function (event) {
event.preventDefault();
alert("Huh");
var email = 'test@theearth.com';
var subject = 'Circle Around';
var emailBody = 'Some blah';
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
});
});
这篇关于jQuery的mailto与锚元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!