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');
}
}
你試過'window.location.href'嗎?那樣有用嗎? – Sukima 2014-10-07 01:55:53
是的,試過了。同樣的錯誤發生。 IE:阻止腳本和Firefox提供了一個錯誤,說:「地址不明白。」 Chrome處理它很好。 – mjbares12 2014-10-07 18:04:51
是你嘗試去的地址在開始時有「my://」嗎? – 2015-04-23 13:43:41