我正在开发Chrome扩展程序。
在我的网站上我是:
windows.open(" website_number_1.html&#34);
然后我的manifest.json是:
"content_scripts": [
{
"matches": ["website_number_1.html"],
"js": ["script1.js"]
},
问题是,我只想在window.open()中打开website_number_1.html时才启动script1.js; 。所以我正在考虑在window.open之后声明一个全局变量,如:
global var launch =" yes&#34 ;;
然后在script1.js中:
if launch == "yes"{
my_script
}
else{
//do nothing
}
非常感谢提前。干杯
答案 0 :(得分:0)
在manifest.json
中"permissions": [
"tabs"
],
在Script1.js
中$(document).ready(function(){
chrome.tabs.getSelected(null,function(tab){
var link = document.createElement('a');
link.href = tab.url;
var host = link.hostname;
var valid_url = "valid url page";
if(host == valid_url){
//Code
}else{
//This is element in HTML of course you can make other function
$("#host").html("This Page is not correct ");
}
})
});
我认为这很好:)
PS: 抱歉我的英文不好