javascript 如果没有电子邮件客户端,`mailto:` 会做什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27176849/
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
What does `mailto:` do when there is no email client?
提问by Edward Karak
I am developing a website.
我正在开发一个网站。
What does mailto:
open in if there is no email client (like Outlook, Thunderbird, etc.)?
It works on my computer, which has Outlook, but what if one wants mailto:
to open in, say, gmail.com?
mailto:
如果没有电子邮件客户端(如 Outlook、Thunderbird 等),会打开什么?它可以在我的电脑上运行,它有 Outlook,但是如果有人想mailto:
在 gmail.com 中打开怎么办?
What do I need to put in the mailto:
statement for that to happen?
我需要在mailto:
声明中加入什么才能做到这一点?
回答by Edward Coyle Jr.
As a web developer you don't have any control over the software that a user chooses to open their email, since it's handled by that user's web browser settings, or the OS. If a user has no email program installed on their machine and no operation defined for "mailto" links in their browser, nothing would happen.
作为 Web 开发人员,您无法控制用户选择打开电子邮件的软件,因为它是由用户的 Web 浏览器设置或操作系统处理的。如果用户没有在他们的机器上安装电子邮件程序并且没有为浏览器中的“mailto”链接定义操作,那么什么都不会发生。
回答by MartijnHoutman
The following solution works for me:
以下解决方案对我有用:
(function($)) {
$('a[href^=mailto]').each(function() {
var href = $(this).attr('href');
$(this).click(function() {
var t;
var self = $(this);
$(window).blur(function() {
// The browser apparently responded, so stop the timeout.
clearTimeout(t);
});
t = setTimeout(function() {
// The browser did not respond after 500ms, so open an alternative URL.
document.location.href = '...';
}, 500);
});
});
})(jQuery);
For more info see: https://www.uncinc.nl/articles/dealing-with-mailto-links-if-no-mail-client-is-available
有关更多信息,请参阅:https: //www.uncinc.nl/articles/dealing-with-mailto-links-if-no-mail-client-is-available
回答by Armand Karambasis
I believe you can use this. https://mail.google.com/mail/?view=cm&fs=1&[email protected]This however does have its flaws in which the user must be already signed into gmail. Hope this helps!
我相信你可以使用这个。https://mail.google.com/mail/?view=cm&fs=1&[email protected]然而,这确实有其缺陷,即用户必须已经登录到 gmail。希望这可以帮助!
回答by Filburt
What happens is entirely up to the client. The OS defines protocol handlers for protocols like mailto:
or tel:
, etc.
发生什么完全取决于客户。操作系统为协议定义了协议处理程序,如mailto:
或tel:
等。
You would need access to the client's registry (in case of a Windows system) to manipulate the handling application for your protocol handler.
您需要访问客户端的注册表(在 Windows 系统的情况下)来操作协议处理程序的处理应用程序。
For Outlook 2013 as the designated handler, the according Registry structure looks like this:
对于作为指定处理程序的 Outlook 2013,相应的注册表结构如下所示:
[HKEY_CLASSES_ROOT\mailto]
@="URL:mailto"
"EditFlags"=hex:02,00,00,00
"URL Protocol"=""
[HKEY_CLASSES_ROOT\mailto\DefaultIcon]
@="C:\PROGRA~2\MICROS~1\Office15\OUTLOOK.EXE,-9403"
[HKEY_CLASSES_ROOT\mailto\shell]
@="open"
[HKEY_CLASSES_ROOT\mailto\shell\open]
[HKEY_CLASSES_ROOT\mailto\shell\open\command]
@="\"C:\PROGRA~2\MICROS~1\Office15\OUTLOOK.EXE\" -c IPM.Note /mailto \"%1\""
with a corresponding structure under HKCU.
HKCU下有相应的结构。
回答by errantlinguist
The mailto
URI scheme doesn't decide what happens-- it simply instructs the browser you're using to do whatever it's been configured to do to send e-mails (see the IETF proposed standard for more info). Therefore, you'll have to consult the browser itself to see what it does if no e-mail client is configured.
该mailto
URI方案并不能决定什么happens--它只是指导你使用做任何它被配置做发送电子邮件,浏览器(见IETF提出更多信息标准)。因此,如果没有配置电子邮件客户端,您将不得不咨询浏览器本身以了解它的作用。
According to the documentation and to my personal experience, I don't see any way of manually setting an action: It might be possible with certain browsers with some non-standard syntax, but this is unlikely since this would open up a huge potential security problem by being able to execute an arbitrary command by click (such as downloading a virus or something like that).
根据文档和我的个人经验,我没有看到任何手动设置操作的方法:使用某些非标准语法的某些浏览器可能是可能的,但这不太可能,因为这会带来巨大的潜在安全性问题在于能够通过单击执行任意命令(例如下载病毒或类似的东西)。