1

我正在使用Microsoft Edge擴展。Microsoft Edge Web導航重定向

我會重定向用戶,如果他們在一個特定的網址導航。 在我background.js腳本我有這樣的:

browser.webNavigation.onBeforeNavigate.addListener(
    function(details) { 
    if(details.url.indexOf("url_path") > -1){ 
    alert("caught"); 
    window.location = "http://new_url.com"; 
    } 
    }  
); 

警報工作,而不是重定向。我做錯了什麼? 也是一個好主意通過用戶通過http auth在重定向? 例如:windows.location =「http://user:[email protected]_url.com」?

謝謝:)

回答

0

browser.webNavigation.onBeforeNavigate被稱爲後臺頁面,當你調用window.location = xxx,窗口是指後臺頁面窗口,這不是當前網頁,這就是爲什麼重定向不起作用。請參閱webRequest.onBeforeRequest。它還提供了有關如何重定向用戶導航的示例代碼。

至於密碼,URL中的HTTP認證,只要您使用HTTPS the entire communication is encrypted.