简体   繁体   中英

Stop running javaScript file in Google Chrome

In my Google Chrome extension it adds a javaScript file or code when the user click on the browser action. ex:

chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null,
                       {code:"document.body.bgColor='red'"});// or any .js code file
});

how can I remove this JavaScript or the code when user click on a button. Assume that there is a code like below triggered when user click on a button.

chrome.tabs.executeScript(null,
                       {file : "tabcolor.js"});

So i want to stop this tabcolor.js execution after User click on the same button. How can I do this ?

Is there any method to stop ExecuteScript ?

Inside your tabcolor.js you have scripts, functions, variables, etc. that execute and do stuff. To make this script "not execute" and not do that stuff, you need to replace the code that does the work. For example:

//tabcolor.js
var banana = function() {
    doMyStuff;
}

If you override the banana function, it will still execute but will accomplish nothing.

banana = null;

This way you replace the code that was inside tabcolor.js and it won't do it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM