2012-11-19 17 views
2

我試圖調用存儲在變量中的mailto: URI。當我做window.location.href = mailto_link;火狐給了我以下錯誤:如果值位於變量中,Firefox和IE將不會調用window.location.href

NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057   
(NS_ERROR_ILLEGAL_VALUE) [nsIDOMLocation.href] 

window.location.href = mailto_link;` 

IE說什麼:

Object doesn't support this property or method 

代碼工作在Chrome但不是在IE也不Firefox瀏覽器。

我原來的功能:

function email() 
{ 
    var nom = $('#nom').val();nom = encodeURIComponent(nom); 
    var compagnie = $('#compagnie').val();compagnie = encodeURIComponent(compagnie); 
    var rue = $('#rue').val();rue = encodeURIComponent(rue); 
    var ville = $('#ville').val();ville = encodeURIComponent(ville); 
    var province = $('#province').val();province = encodeURIComponent(province); 
    var cp = $('#cp').val();cp = encodeURIComponent(cp); 
    var remarques = $('#remarques').val();if(remarques ==""){remarques = "Aucune remarque.";}remarques = encodeURIComponent(remarques); 
    var quantite = $('#quantite').val(); 
    var email= "[email protected]"; 
    var subject= "Nouvelle commande"; 
    var body_message= "%0D%0D%0D%0D"+nom+"%0D"+compagnie+"%0D"+rue+"%0D"+ville+", "+province+"%0D"+cp+"%0D%0D%0DRemarques:"+remarques+"%0D%0D Quantit%E9:"+quantite; 
    var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message; 
    window.location.href = mailto_link; 
} 

更新1

我發現了什麼導致了問題的IE瀏覽器,雖然我還在尋找解決它爲Firefox。對於IE的問題是,我有一個console.log();這將不會被識別(IE8和更低版本)。

這裏是MAILTO_LINK的內容的console.log()

mailto:[email protected]?subject=Nouvelle commande&body=Charger %0Dmodems des %CEseulement%0D%0D%0D%0Djshad%0Daskjda%0Daskdj%0Daskdj, askdj%0DJ9P%204A1%0D%0D%0DRemarques:asldk%0D%0D Quantit%E9:14 
+0

編輯:剛試過在Mac上,它適用於Firefox和Chrome。無法測試IE ...你確定變量中沒有東西嗎? – romo

+0

您在IE中遇到什麼錯誤? –

+0

「email」,「subject」和「body_message」變量的值究竟是什麼?你應該對這些值使用'encodeURIComponent()'。 – Pointy

回答

1

Firefox是顯然無法處理ISO 8859-1字符以上128中的URL。如果您從記錄的示例中刪除%CE(Î)和%E9(é),問題就會消失。不幸的是,我能想到的唯一解決方法是需要手動替換擴展字符,例如具有等效字符(可能是HTMLEntities *)的擴展字符。由於在Javascript中沒有本地函數,所以這可能會讓人很煩惱。

**由於HTMLEntities只能在HTML上下文中正確呈現,並且mailto:URI會生成純文本消息正文,所以這是一個不完美的解決方案。下面是一個可以做到這一點的函數,但是這個消息將會有é之類的實例。也許更方便的解決方案是convert accented characters to their equivalents in the first 128 ASCII characters當你在評論中提到*


function encodeISO8859 (str) { 
    var rstr=""; 
    for(var i=0; i<str.length; i++) { 
     var c = str.charCodeAt(i); 
     if(c>191&&c<=255&&!(c==215||c==247)){ 
      console.log(c); 
      rstr += "&#"+c+";"; 
     } else { 
      rstr += str.charAt(i); 
     } 
    } 
    return rstr; 
} 

這將打開在ISO8859-1 character set任何字符(見頁面底部)爲它的等效HTMLEntity。使用此之前,URI編碼:

var nom = $('#nom').val();nom = encodeURIComponent(encodeISO8859(nom)); 

當然,只有這樣做,如果重音字符是理解絕對必要的,而且有可能是使用相同的基本字符(如A)許多口音之間的重疊。

0

我想這和它的工作對我來說,但我認爲錯誤代碼可能與您可以在Firefox中已安裝的插件之一或IE,重新啓動瀏覽器應該有所幫助。

this is probably caused by an addon/userscript which is doing some operations/modifications on the page while google redirects you do a search result. you can try to run firefox in Troubleshoot Firefox issues using Safe Mode and see if the error still occurs there. if not disable all your addons & reenable them one in order to find out which one is causing it exactly (you'll likely have to do a restart of the browser after each one).

MORE

+0

它並沒有改變Firefox的情況(令人傷心),而IE有一個不同的問題,現在已經修復。感謝您的貢獻。 –

相關問題