我正在制作一个非常简单的 Chrome 扩展程序,它将 http 协议上的页面重定向到 https 协议(如果存在)。我正在调试,我发现了 facebook,它同时具有 http 和 https。
代码在这里:
function redirect() {
chrome.tabs.query({active: true}, function(tabArray) {
var currentURL = tabArray[0].url; //http://facebook.com
var httpsURL = generateSSL(currentURL); //https://facebook.com
if(httpsURL == currentURL){
console.log(currentURL+" is already on HTTPS");
chrome.browserAction.setIcon({path:"../images/padlock_green.png"});
} else if(checkSSL(httpsURL)){
chrome.tabs.update(tabArray[0].id, {url: httpsURL});
chrome.browserAction.setIcon({path:"../images/padlock_green.png"});
chrome.browserAction.setBadgeText({text:"SSL"});
console.log("SSL found,"+currentURL+" redirected to"+httpsURL);
} else {
//donothing
console.log(currentURL+" has no SSL");
chrome.browserAction.setIcon({path:"../images/padlock_red.png"});
}
});
}
阿贾克斯调用:
function checkSSL(url){
$.support.ajax = true;
$.ajax({
url: url,
type:'HEAD',
error: function()
{
return false;
},
success: function()
{
return true;
}
});
}
问题是,我在控制台中收到以下错误消息:
XMLHttpRequest cannot load https://www.facebook.com/. Origin chrome-extension://pgidanbjmliilmmohlphbagcapafjjpg is not allowed by Access-Control-Allow-Origin.
我不知道可能是什么问题:(