How can I import a file while executing a content script in a chrome extension? -


i want execute javascript have background.html page set

<html>   <head>     <script type="text/javascript" src="jquery.js"></script>    </head>   <body>         <script type="text/javascript" src="jquery.js"></script>      <script>     chrome.browseraction.onclicked.addlistener(function(tab) {         chrome.tabs.executescript(null, {file: "contentscript.js"});     });     </script>   </body> </html> 

i use jquery in script, can't figure out how load. don't want content script go off every time user loads pages, when click extension's button. ideas?

chrome.tabs.executescript method has third parameter callback function executes when script loaded, can use load more 1 script in order:

chrome.browseraction.onclicked.addlistener(function(tab) {     chrome.tabs.executescript(null, {file: "jquery.js"}, function() {         chrome.tabs.executescript(null, {file: "contentscript.js"});     }); }); 

you don't need include <script type="text/javascript" src="jquery.js"></script> background page if don't plan using there.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -