使用html5& amp;动态生成的主体创建电子邮件链接JavaScript的

问题描述:

我试图创建一个链接来创建一个电子邮件,以向用户发送信息,其身体需要填充由javascript函数生成的数据,并希望有人能够帮助。

Am trying to create a link to create an email to send information to the user, the body of which needs to be filled with data generated by a javascript function, and hope that someone can help.

如果我可以用下面的body_blurb替换一个从点击完成之后调用的JavaScript函数返回的字符串,那么它是非常理想的。

Idealy, if I could substitute the 'body_blurb' below, with a string returned from a javascript function called at the time of clicking that'd be perfect.

<A HREF="mailto:you@yourdomain.com?subject=Data&body=body_blurb">e-mail data</a>

欣赏你的时间

我刚刚在这里分配了一个id到链接,但是如果你想要的话,你可以创建一些更通用的东西。创建一个onclick处理程序后,您可以使用 href 访问该URL。将其设置为任何您想要的。

I just assigned an id to the link here, but you could create something more generic if you wanted. Once you have an onclick handler created you can access the url with href. Set this to whatever you want.

http://jsfiddle.net/f3ZZL/1

var link = document.getElementById('email');
link.onclick = function() {
    this.href = "mailto:you@yourdomain.com?subject=Data&body=";
    this.href += getBody();
};

function getBody() {
    return 'HelloWorld';
}