Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load JQuery into a Chrome extension?

I'm attempting to load JQuery into my Chrome extension and make it equal to an object but I'm wondering how would I go about this? basically I'd like something like...

jQuery = loadLibraries("jquery-1.4.2.min.js"); 

How would I do this?

edit: I'm injecting into content script.

like image 452
Skizit Avatar asked Feb 09 '11 16:02

Skizit


People also ask

How do I get jQuery in chrome?

Load jQuery into your current page by copying and pasting the following code into your Chrome Console. var jqry = document. createElement('script'); jqry. src = "https://code.jquery.com/jquery-3.3.1.min.js"; document.

Can you import jQuery in a JavaScript file?

Your JavaScript file ( scripts. js ) must be included below the jQuery library in the document or it will not work. Note: If you downloaded a local copy of jQuery, save it in your js/ folder and link to it at js/jquery. min.

Can you add jQuery to HTML?

Step 1: Open the HTML file in which you want to add your jQuery with the help of CDN. Step 2: Add <script> tag between the head tag and the title tag which will specify the src attribute for adding your jQuery. Step 3: After that, you have to add the following path in the src attribute of the script tag.

Which extension is used for jQuery?

jquery.min.js The minified version of the jQuery you need to use.


1 Answers

You can just put jquery.js into extension folder and include it in the manifest:

{   "name": "My extension",   ...   "content_scripts": [     {       "matches": ["http://www.google.com/*"],       "css": ["mystyles.css"],       "js": ["jquery.js", "myscript.js"]     }   ],   ... } 

You don't need to worry about conflicts with jQuery on a parent page as content scripts are sandboxed.

like image 53
serg Avatar answered Sep 20 '22 13:09

serg