3

我想通过提供 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 扩展程序在选项卡中调用之前不会被调用或更改其请求?

提前致谢。

4

1 回答 1

5

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

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

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

chrome.extension.onBeforeRequest.addListener(function() { return {cancel: true} },
  { urls: ["http://www.test.com/alter.php"] },
  ["blocking"]
);
于 2012-05-30T14:44:02.127 回答