2014-10-07 47 views
1

嘗試讓網頁管理重定向,如果深度鏈接無法打開。如果深度鏈接打開,很好。如果它不在2秒內,我希望它進入我的網站。除Chrome之外的所有重定向javascript都失敗

 <script type="javascript"> 
    setTimeout(function() { window.location = "http://mywebsite.com"; }, 25); 
    window.location = "my://app";  
    </script> 

我已經在Chrome中測試過,它可以正常工作,但是Firefox,IE和Safari都會阻止腳本。

任何人有任何想法如何處理?

+0

你試過'window.location.href'嗎?那樣有用嗎? – Sukima 2014-10-07 01:55:53

+0

是的,試過了。同樣的錯誤發生。 IE:阻止腳本和Firefox提供了一個錯誤,說:「地址不明白。」 Chrome處理它很好。 – mjbares12 2014-10-07 18:04:51

+0

是你嘗試去的地址在開始時有「my://」嗎? – 2015-04-23 13:43:41

回答

0

window.location.assign(「http:mywebsite.com」)可能是一個更好的選擇,因爲我相信調用該函數會觸發一些額外的事件,可能會使頁面的生命週期易於管理。

此外,除了Chrome之外,您可以使用IFrame嘗試啓動協議處理程序。這將有助於防止頁面轉向:空白和/或腳本因導航離開頁面而停止。

var createIframe = function(id, url, timeout, callback) { 
    var iframe; 
    iframe = document.createElement("iframe"); 
    iframe.hidden = true; 
    iframe.id = id; 
    iframe.src = url; 

    var data = {} 
    data.id = id; 
    data.iframe = iframe; 
    return setTimeout(callback, timeout, null, data); 
} 

createIframe('tempFrame', 'http://mywebsite.com', 25, function(err, data) { 
    if(!err && data){ 
     var iframe = data.iframe; 
     var id = data.id; 
     iframe = document.getElementById(id); 
     iframe.parent.removeChild(iframe); 
    } 
    else { 
    console.log('There was an error createing and removeing the iframe'); 
    } 
}