admin管理员组文章数量:1426597
I have by default an External JS called alerton that will run on anywebppage when the extension is enabled. I've also set up a Popup/Menu for when you click the Chrome Extension Icon at the top right. I want to when the user presses the button "off" to Turn off/Remove an external javascript file called "alerton"
After many many hours, I'm at a loss as to what I need to do to get this to work! I've looked at chrome.contentSettings.javascript However it doesn't seem like I can disable just one particular Javascript file.
I'm hoping someone has an answer...
I have by default an External JS called alerton that will run on anywebppage when the extension is enabled. I've also set up a Popup/Menu for when you click the Chrome Extension Icon at the top right. I want to when the user presses the button "off" to Turn off/Remove an external javascript file called "alerton"
After many many hours, I'm at a loss as to what I need to do to get this to work! I've looked at chrome.contentSettings.javascript However it doesn't seem like I can disable just one particular Javascript file.
I'm hoping someone has an answer...
Share Improve this question asked May 18, 2013 at 3:01 f00df00d 5811 gold badge7 silver badges21 bronze badges1 Answer
Reset to default 5One way you could achieve this is by reading and modifying a boolean variable in a Background Page and use Message Passing to municate to and from your content-script and popup page. You can define a Background Page in your Manifest as such:
....
"background": {
"scripts": ["background.js"]
},
....
The background.js would look something like this:
var isExtensionOn = true;
chrome.extension.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.cmd == "setOnOffState") {
isExtensionOn = request.data.value;
}
if (request.cmd == "getOnOffState") {
sendResponse(isExtensionOn);
}
});
From your PopUp.html and your content-script you could then call the background.js to read and set the isExtensionOn
variable.
//SET VARIABLE
var isExtensionOn = false;
chrome.extension.sendMessage({ cmd: "setOnOffState", data: { value: isExtensionOn } });
//GET VARIABLE
chrome.extension.sendMessage({ cmd: "isAutoFeedMode" }, function (response) {
if (response == true) {
//Run the rest of your content-script in here..
}
});
本文标签: javascriptStop a Google Chrome Extensions with a On and Off Button HowStack Overflow
版权声明:本文标题:javascript - Stop a Google Chrome Extensions with a On and Off Button. How? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745482265a2660227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论