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.