我正在尝试创建一个查询外部源的chrome扩展,作为阻止或允许通过特定页面的引用。以下是我的代码的一部分。我是JavaScript新手,范围似乎总是让我兴奋不已。Chrome扩展webRequest.onBeforeRequest取消页面
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
var http = new XMLHttpRequest();
var url = "http://xxx.xx.xxxx";
var params = "urlCheck="+encodeString_(details.url);
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
guilt = 0;
console.log(guilt);
}else if(http.readyState == 4 && http.status == 404){
guilt = 1;
console.log(guilt);
}
}
http.send(params);
if(guilt == 1){
return {cancel: true};
}else{
return {cancel: false};
}
},
{urls: ["<all_urls>"],
types:["main_frame"]
},
["blocking"]
);
任何帮助将不胜感激!谢谢。
那么你真正的问题是什么?什么不工作或者你是否收到错误信息,如果是这样,告诉我们它是什么 – RiggsFolly 2015-04-01 15:06:42