简体   繁体   English

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

[英]Webkit Browsers (Chrome and Safari) don't like mailto?

Below is my code: 以下是我的代码:

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

    if(subject == "Website Feedback"){
        to = to + "; augustoandrew@gmail.com";
    }

    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 ^^以下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, 'bibbidy@judys.com', 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. 我遇到的问题是在Internet Explorer和Firefox中,这段代码完美无缺。 In Safari and Chrome, it won't work. 在Safari和Chrome中,它无法使用。 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. 正如您所看到的,它只能使用mailto与Outlook和Live(桌面版)一起使用。 Gmail I'm not sure works yet. Gmail我还不确定。 If anyone can help me to know why the webkit browsers aren't recognizing this code, please do. 如果有人可以帮助我知道为什么webkit浏览器无法识别此代码,请执行此操作。

try window.location.href='mailto:marco@h4kr.com'; 尝试window.location.href ='mailto:marco@h4kr.com'; ;) ;)

works for chrome 12 ;) haven't tested it in safari :) 适用于chrome 12;)尚未在safari中测试过:)

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";

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拖放禁用在Safari / Chrome WebKit浏览器中不起作用 - Drag-Drop disabling not working in Safari/Chrome WebKit Browsers 在调整大小时,Chrome和Safari无法可靠地更新样式(Webkit错误?) - During resize Chrome and Safari don't update styles reliably (webkit bug?) Anchor在Chrome和Safari浏览器中不起作用 - Anchor doesn't work in chrome and safari browsers 如何在webkit浏览器中删除c伪路径,如chrome,safari,opera? - how to remove c fakepath in webkit browser like chrome, safari, opera? IOS:8822996504788 cookie 在 ios 浏览器(如 safari 或 chrome)上不起作用 - IOS: javascript cookie not working on ios browsers like safari or chrome 使用JavaScript检查浏览器的方法,如window,safari和chrome - Way to use JavaScript to check browsers such like window, safari and chrome 如何确定Webkit Chrome和Safari浏览器的图像高度和宽度? - How do you determine an image height and width for webkit Chrome and Safari browsers? 视频循环自动播放在 Chrome/safari 上不起作用(webkit 错误) - Video loop autoplay won't work on Chrome/safari (webkit bug) “颜色动画插件”在webkit(Safari浏览器Chrome)上不起作用 - the 'Color Animations plugin' doesn't work on webkit(safari chrome) 内联onchange提交不适用于webkit(Chrome或Safari) - Inline onchange submit doesn't work with webkit (Chrome or Safari)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM