javascript 通过javascript打开电子邮件客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22941457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
open email client through javascript
提问by nick
is there anyway through which I can open more than one email client, (on a single click) in java script, I know how to use mailto but don't know how to open multiple clients this code opens the client on each reload.
无论如何我可以在java脚本中打开多个电子邮件客户端(单击一次),我知道如何使用mailto但不知道如何打开多个客户端此代码在每次重新加载时打开客户端。
window.location.href = "mailto:[email protected]?subject=Subject&body=message%20goes%20here";
Any help in this regard Thanks
在这方面的任何帮助谢谢
回答by nick
If you want it to load the mail client on a click rather than every time the page refreshes, you want it attached to a click event, something like this : http://jsfiddle.net/G7Ws7/
如果您希望它在单击时加载邮件客户端而不是每次刷新页面时,您希望它附加到一个单击事件,如下所示:http: //jsfiddle.net/G7Ws7/
<button class="button">Open Email</button>
Using jQuery :
使用 jQuery :
$(document).ready(function(){
$('.button').on('click',function(){
window.location.href = "mailto:[email protected]?subject=Subject&body=message%20goes%20here";
});
});
Update
更新
If you want it to load multiple instances of the client, just duplicate the window.location.href
: http://jsfiddle.net/G7Ws7/1/
如果您希望它加载客户端的多个实例,只需复制window.location.href
:http: //jsfiddle.net/G7Ws7/1/
$(document).ready(function(){
$('.button').on('click',function(){
window.location.href = "mailto:[email protected]?subject=Subject&body=message%20goes%20here";
window.location.href = "mailto:[email protected]?subject=Subject2&body=message%20goes%20here";
});
});
回答by phylax
It is not possible to launch external applications from JavaScript in a Browser. mailto only launches the MUA which is configured as the default in the system-settings.
无法在浏览器中从 JavaScript 启动外部应用程序。mailto 仅启动在系统设置中配置为默认值的 MUA。