2011-06-17 27 views
4

下面是我的代碼:Webkit瀏覽器(Chrome和Safari)不喜歡mailto?

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下面的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> 

我遇到的問題是,在Internet Explorer和Firefox,此代碼的工作非常完美。在Safari和Chrome中,它將無法工作。它基本上只是重新加載頁面,但沒有任何反應。正如你所看到的,它只能設置爲使用mailto與Outlook和Live(桌面版)一起工作。 Gmail我還不確定。如果有人能幫助我瞭解爲什麼webkit瀏覽器不能識別此代碼,請做。

+0

我不確定瀏覽器,但我知道我不喜歡mailto鏈接! SCNR – 2011-06-17 13:32:46

+0

請注意:使用`mailto`要求用戶正在使用的計算機配置了郵件客戶端。今天,許多用戶使用Web客戶端,因此它不會工作。更好的解決方案是將表單發送回服務器(在form-tag中使用`method ='post'`)並在那裏處理數據。它的速度也快得多,因爲在你回來之前,你不必等待郵件通過所有的郵件服務器。 – some 2011-06-17 13:43:58

回答

1

感謝很大的幫助我也從上面的代碼中一些幫助終於完成了。

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

} 
相關問題