[英]Set global variables between scripts in chrome extension
I'm developping a chrome extension. 我正在开发chrome扩展程序。
In my website i've a: 在我的网站上,我有:
windows.open("website_number_1.html");
windows.open(“ website_number_1.html”);
Then my manifest.json is: 然后我的manifest.json是:
"content_scripts": [
{
"matches": ["website_number_1.html"],
"js": ["script1.js"]
},
The thing is, i want to launch script1.js only if the website_number_1.html is being opened from the window.open(); 问题是,仅当从window.open()打开website_number_1.html时,我才想启动script1.js。 .
。 So i was thinking about declaring a global variable just after the window.open like:
所以我正在考虑在window.open之后声明一个全局变量,例如:
global var launch = "yes";
global var launch =“是”;
and then in script1.js: 然后在script1.js中:
if launch == "yes"{
my_script
}
else{
//do nothing
}
Thanks very much in advance. 首先十分感谢。 Cheers
干杯
In manifest.json 在manifest.json中
"permissions": [
"tabs"
],
In Script1.js 在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 ");
}
})
}); });
I think that this is good :) 我认为这很好:)
PS: sorry for my bad English PS:对不起,我的英语不好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.