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 #ifndef is to include guards in C.

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:

  if (! Window.contentScriptInjected) {ContentScriptInjected = true; // global scope / * your initial work and work * /} / * global function definitions * /    

Comments

Post a Comment

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -