检测基于Web的邮件客户端与本地邮件客户端的邮件链接 [英] Detecting web-based mail client vs local mail client for a mailto link

查看:184
本文介绍了检测基于Web的邮件客户端与本地邮件客户端的邮件链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,用户可以通过该应用程序使用mailto链接发送电子邮件。基本上,我连接一个包含主题,正文和收件人的字符串,然后代码触发mailto,有点像这样:

I have a web application from which the user can send an email using a mailto link. Basically, I concatenate a string that contains the subject, body and recipients and then the code triggers a mailto, somewhat like this:

var MailToLink = 'mailto:' + TheEmailString;

window.open(MailToLink, '_blank'); //option 1
window.open(MailToLink); //option 2

最初,我只有选项2,因为在我的开发机器上我有Outlook。但是当我开始一些alpha测试时,另一个用户正在使用Gmail,并且mailto链接将在与我的应用程序相同的窗口中打开,所以我将代码更改为选项2,以便电子邮件在另一个窗口中打开。现在的问题是,当用户在Outlook上时,该链接将打开一个Outlook消息和一个新的空白窗口。

Initially, I only had option 2 because on my dev machine I have Outlook. But as I started some alpha testing, another user was using Gmail and the mailto link would open in the same window as my app so I changed my code to option 2 so that the email opens in another window. The problem now is that when the user is on Outlook, the link opens both an Outlook message and a new blank window.

有没有办法检测用户是否使用基于Web的电子邮件客户端或本地客户端?我想做这样的事情:

Is there a way to detect if the user is using a web-based email client or a local client? I would like to do something like this:

if (IsUsingWebMailClient) {

    window.open(MailToLink, '_blank');

} else {

    window.open(MailToLink);
}

我不知道这是否可能,但如果是这样的话很棒:如何使用javascript检测mailto客户端?

I'm not sure if this is even possible but if it is that would be great: how do I detect the mailto client using javascript?

谢谢。

推荐答案

这是一个 hack ,但是有效。超时可能会有所不同,您可以用越来越少的毫秒进行测试。

It's a bit of a hack, but that works. The time out may vary, you can test with more and less milliseconds.

<html>
    <head>
        <script type="text/javascript">
            function mailTo(address){
                var windowRef = window.open('mailto:'+address, '_blank');
                var body = windowRef.document.getElementsByTagName('body')
                if(!body.lenth) setTimeout(windowRef.close,300)
            }
        </script>
    </head>
    <body>

    <input type="button" value="send email" onclick="mailTo('email@gmail.com')" >

    </body>
</html>

这篇关于检测基于Web的邮件客户端与本地邮件客户端的邮件链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆