javascript - How to load jQuery in Google Chrome Extensions -
i can't jquery in simple google chrome extension picked when click on extension icon. i've searched quite bit how this, can't figure out why not working me.
i think jquery sound because works without onclicked function, prefer work once icon has been clicked.
edit: have jquery included in project file called "jquery.js"
my manifest.json looks this:
{ "name": "test", "description": "test", "version": "1.0", "permissions": [ "activetab", "http://*/*", "https://*/*", "https://ajax.googleapis.com/" ], "content_scripts": [ { "matches": ["*://*/"], "js": ["scripts/jquery.js", "scripts/script.js", "scripts/background.js"] } ], "background": { "scripts": ["scripts/jquery.js","scripts/script.js", "scripts/background.js"] }, "browser_action": { "default_title": "test", "default_icon": "image.png" }, "manifest_version": 2
}
background.js this:
chrome.browseraction.onclicked.addlistener(function(tab) {
chrome.tabs.executescript(tab.id, { file: "scripts/jquery.js", allframes: true, runat: "document_idle" }); chrome.tabs.executescript(tab.id, { file: "scripts/script.js", allframes: true, runat: "document_idle" }); });
and script.js this:
chrome.browseraction.onclicked.addlistener(function(tab) { alert("hey!"); $('html *:not(script, style, noscript)').each(function() { $(this).css("background", "pink"); }); });
i know function being called browser because alert gets picked when icon clicked, none of jquery. suggestions how fix this/what may wrong code?
thanks
according manifest file provided, background.js , jquery.js in same folder, should import jquery.js right path in background.js:
chrome.tabs.executescript(tab.id, { file: "jquery.js", allframes: true, runat: "document_idle" }); chrome.tabs.executescript(tab.id, { file: "script.js", allframes: true, runat: "document_idle" }); });
Comments
Post a Comment