我想通过提供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.
});
是否可以屏蔽网址,以便在通过Google扩展程序在标签中调用之前不会调用或更改其请求?
提前感谢。
答案 0 :(得分:5)
您可以在阻止模式下使用chrome.webRequest的onBeforeRequest方法来取消导航。
您的清单需要声明“webRequest”和“webRequestBlocking”的权限。
然后添加一个挂钩onBeforeRequest的后台脚本,并取消该URL的导航:
chrome.extension.onBeforeRequest.addListener(function() { return {cancel: true} },
{ urls: ["http://www.test.com/alter.php"] },
["blocking"]
);