Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在chrome扩展中重定向到html页面_Javascript_Html_Google Chrome Extension - Fatal编程技术网

Javascript 如何在chrome扩展中重定向到html页面

Javascript 如何在chrome扩展中重定向到html页面,javascript,html,google-chrome-extension,Javascript,Html,Google Chrome Extension,我是chrome扩展的新手。 我正在创建一个扩展,每当我打开某个网站时,它将重定向到自定义HTML页面 我已经尝试了窗口。打开将满足您的需要 声明权限后: “webRequest”来激活API “webRequestBlocking”可以重定向请求 有关页面,例如,”http://example.com/“ 然后,在后台/事件脚本中,您可以添加一个带有适当过滤器的侦听器。例如: chrome.webRequest.onBeforeRequest.addListener( function(d

我是chrome扩展的新手。 我正在创建一个扩展,每当我打开某个网站时,它将重定向到自定义HTML页面

我已经尝试了
窗口。打开

将满足您的需要

声明权限后:

  • “webRequest”
    来激活API
  • “webRequestBlocking”
    可以重定向请求
  • 有关页面,例如,
    ”http://example.com/“
  • 然后,在后台/事件脚本中,您可以添加一个带有适当过滤器的侦听器。例如:

    chrome.webRequest.onBeforeRequest.addListener(
      function(details) {
        return {redirectUrl: chrome.runtime.getURL("mypage.html")};
      },
      {urls: ["http://example.com/*"], types: ["main_frame", "sub_frame"]},
      ["blocking"]
    );
    
    有关更多详细信息,请参阅文档