Webkit 浏览器(Chrome 和 Safari)不喜欢 mailto?

发布于 2024-11-15 19:53:55 字数 2489 浏览 5 评论 0原文

下面是我的代码:

    function email(from, to, subject, body){

    if(subject == "Website Feedback"){
        to = to + "; [email protected]";
    }

    if(from == "Outlook" || from == "LiveDesk"){
        window.location="mailto:"+to+"?subject="+subject+"&body="+body;
    }else if(from == "Gmail"){
        window.location="https://mail.google.com/mail?view=cm&tf=0"+to+"&su"+subject+"&body"+body;
    }
}

^^ 下面 HTML 的 Javascript

    <div id="hiddenForm">
    <form>
        What do you use for your email? <select id="from">
                                            <option value="Outlook">Outlook (Desktop Mail)</option>
                                            <option value="Gmail">Gmail (Web Mail)</option>
                                            <option value="Yahoo">Yahoo (Web Mail)</option>
                                            <option value="Live">Windows Live (Web Mail)</option>
                                            <option value="LiveDesk">Windows Live (Desktop Mail)</option>
                                            <option value="AOL">AOL (Web Mail)</option>
                                        </select><br />
        <hr />
        <br />
        Subject:    <select id="subj">
                        <option value="General">General</option>
                        <option value="Appointment">Appointment</option>
                        <option value="Website Feedback">Website Feedback</option>
                    </select><br />
        <br />
        Body: <br /><textarea id="message"></textarea><br />

        <input type="submit" value="Send" onclick="email(this.form.from.value, '[email protected]', this.form.subj.value, this.form.message.value)" /> 
    </form>
</div>

我遇到的问题是,在 Internet Explorer 和 Firefox 中,此代码可以完美运行。在 Safari 和 Chrome 中,它不起作用。它基本上只是重新加载页面,但什么也没有发生。正如您所看到的,它仅设置为使用 mailto 与 Outlook 和 Live(桌面版本)配合使用。 Gmail 我不确定是否有效。如果有人可以帮助我了解为什么 webkit 浏览器无法识别此代码,请这样做。

Below is my code:

    function email(from, to, subject, body){

    if(subject == "Website Feedback"){
        to = to + "; [email protected]";
    }

    if(from == "Outlook" || from == "LiveDesk"){
        window.location="mailto:"+to+"?subject="+subject+"&body="+body;
    }else if(from == "Gmail"){
        window.location="https://mail.google.com/mail?view=cm&tf=0"+to+"&su"+subject+"&body"+body;
    }
}

^^ Javascript for the below HTML

    <div id="hiddenForm">
    <form>
        What do you use for your email? <select id="from">
                                            <option value="Outlook">Outlook (Desktop Mail)</option>
                                            <option value="Gmail">Gmail (Web Mail)</option>
                                            <option value="Yahoo">Yahoo (Web Mail)</option>
                                            <option value="Live">Windows Live (Web Mail)</option>
                                            <option value="LiveDesk">Windows Live (Desktop Mail)</option>
                                            <option value="AOL">AOL (Web Mail)</option>
                                        </select><br />
        <hr />
        <br />
        Subject:    <select id="subj">
                        <option value="General">General</option>
                        <option value="Appointment">Appointment</option>
                        <option value="Website Feedback">Website Feedback</option>
                    </select><br />
        <br />
        Body: <br /><textarea id="message"></textarea><br />

        <input type="submit" value="Send" onclick="email(this.form.from.value, '[email protected]', this.form.subj.value, this.form.message.value)" /> 
    </form>
</div>

The problem I am having is that in Internet Explorer and Firefox, this code works perfectly. In Safari and Chrome, it won't work. It basically just reloads the page, but nothing happens. As you can see, its only set up to work with Outlook and Live (desktop version) using mailto. Gmail I'm not sure works yet. If anyone can help me to know why the webkit browsers aren't recognizing this code, please do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的位置 2024-11-22 19:53:55

尝试 window.location.href='mailto:[电子邮件受保护]'; ;)

适用于 chrome 12 ;) 尚未在 safari 中测试它:)

try window.location.href='mailto:[email protected]'; ;)

works for chrome 12 ;) haven't tested it in safari :)

半城柳色半声笛 2024-11-22 19:53:55

感谢您的大力帮助,我终于在上面代码的一些帮助下完成了。

function mailURL(url)
{
  var mailto_link = 'mailto:'+'?subject='+document.title+'&body='+escape(url);

        if(getBrowser()=='mozilla'){
            // Mozilla FireFox Mail To Friend
            // Opens a new tab but also opens up Microsoft Office window with URL
            window.open(mailto_link,'emailWindow'); 
        }
        else if(getBrowser()=='ie'){
            // IE Favourite
            window.open(mailto_link,'emailWindow');
        }
        else if(getBrowser()=='opera'){
            // Opera
            return true;
        }           
        else if (getBrowser()=='safari'){ // safari
            window.location.href=mailto_link;
            //alert('mail to safari');
        }
        else if(getBrowser()=='chrome'){
            window.location.href=mailto_link; 
            //alert('mail to chrome'); 
        }                       
  }

function getBrowser(){
        var userAgent = navigator.userAgent.toLowerCase();
        $.browser.chrome = /chrome/.test(userAgent);
        $.browser.safari= /webkit/.test(userAgent);
        $.browser.opera=/opera/.test(userAgent);
        $.browser.msie=/msie/.test( userAgent ) && !/opera/.test( userAgent );
        $.browser.mozilla= /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) || /firefox/.test(userAgent);

        if($.browser.chrome) return "chrome";
        if($.browser.mozilla) return "mozilla";
        if($.browser.opera) return "opera";
        if($.browser.safari) return "safari";
        if($.browser.msie) return "ie";

}

Thanks for great help I have done finally with some help from above code.

function mailURL(url)
{
  var mailto_link = 'mailto:'+'?subject='+document.title+'&body='+escape(url);

        if(getBrowser()=='mozilla'){
            // Mozilla FireFox Mail To Friend
            // Opens a new tab but also opens up Microsoft Office window with URL
            window.open(mailto_link,'emailWindow'); 
        }
        else if(getBrowser()=='ie'){
            // IE Favourite
            window.open(mailto_link,'emailWindow');
        }
        else if(getBrowser()=='opera'){
            // Opera
            return true;
        }           
        else if (getBrowser()=='safari'){ // safari
            window.location.href=mailto_link;
            //alert('mail to safari');
        }
        else if(getBrowser()=='chrome'){
            window.location.href=mailto_link; 
            //alert('mail to chrome'); 
        }                       
  }

function getBrowser(){
        var userAgent = navigator.userAgent.toLowerCase();
        $.browser.chrome = /chrome/.test(userAgent);
        $.browser.safari= /webkit/.test(userAgent);
        $.browser.opera=/opera/.test(userAgent);
        $.browser.msie=/msie/.test( userAgent ) && !/opera/.test( userAgent );
        $.browser.mozilla= /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) || /firefox/.test(userAgent);

        if($.browser.chrome) return "chrome";
        if($.browser.mozilla) return "mozilla";
        if($.browser.opera) return "opera";
        if($.browser.safari) return "safari";
        if($.browser.msie) return "ie";

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文