javascript - Avoid dynamically injecting the same script multiple times when using chrome.tabs.executeScript(...) -
I'm building a Google Chrome extension In the original setup, I have a browser action button that works in the active tab in jQuery and Injects the second bit of JavaScript, when it is clicked to do it
This is my first chrome extension, but it seems that the user will take a second action on the script again Will be injected from This is a problem because the main pages are working with all AJAX, so there is a lot of change in the content of the page but the actual page URL has never changed.
Is this a legitimate concern, or am I thinking this is an easy way to stop script by injection multiple times and in a script? Should I perhaps specify them as content scripts?
This is absolutely legitimate concern.
The easiest way to use a system like the Once the content script is executed, a flag is set, and check whether it is defined before doing anything, by executing all the scripts in the same detail, JS execution reference and therefore global field sharing Please. Your content script may look like this: #ifndef is to include guards in C.
if (! Window.contentScriptInjected) {ContentScriptInjected = true; // global scope / * your initial work and work * /} / * global function definitions * /
html उदाहरण कोड
ReplyDeleteएंकर डिस्प्ले ब्लॉक कोड स्निपेट