Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
Google chrome extension 在选项卡中查看URL并阻止它,使其不会';在发送之前,不要呼叫或更改它_Google Chrome Extension - Fatal编程技术网

Google chrome extension 在选项卡中查看URL并阻止它,使其不会';在发送之前,不要呼叫或更改它

Google chrome extension 在选项卡中查看URL并阻止它,使其不会';在发送之前,不要呼叫或更改它,google-chrome-extension,Google Chrome Extension,我想通过提供URL地址来阻止要调用的URL,例如: 这不管用,但像这样的东西 $.watch("http://www.test.com/alter.php",function(){ //It was called here return false; //This in this scenario would block the URL to be called, it would cancel its request, it wouldn't even send the req

我想通过提供URL地址来阻止要调用的URL,例如:

这不管用,但像这样的东西

$.watch("http://www.test.com/alter.php",function(){
    //It was called here
    return false; //This in this scenario would block the URL to be called, it would cancel its request, it wouldn't even send the request, it would cancel before it access the web.
});
有没有可能阻止一个URL,这样它就不会被调用,或者在通过Google扩展在标签中调用它之前改变它的请求


提前感谢。

您可以在阻止模式下使用chrome.webRequest的方法来取消导航

您的清单将需要声明“webRequest”和“webRequestBlocking”的权限

然后添加一个后台脚本,该脚本钩住BeforeRequest并仅取消该URL的导航:

chrome.extension.onBeforeRequest.addListener(function() { return {cancel: true} },
  { urls: ["http://www.test.com/alter.php"] },
  ["blocking"]
);

然而,导航似乎发生了。不会发送请求,但浏览器的UI部分仍将“尝试导航”。即,出现“此网页被扩展阻止”错误