我做了一个非常简单的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"});
}
});
}
Ajax调用:
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.
我没有任何想法可能是什么问题:(
好像你的扩展正在发出Ajax请求... – 2012-04-16 12:02:06
sry,我忘了复制ajax调用,我更新了我的帖子:/ – 2012-04-16 12:05:18
但是,这个Ajax调用是问题...你不能这样做,这就是错误信息所说的。此外,您不能从Ajax回调中返回值,整个设置将无法工作。您必须找到其他方式来测试HTTPS版本是否可用。 – 2012-04-16 12:07:45