I am making a [PageAction](http://code.google.com/chrome/extensions/pageAction.html) Chrome extension with a popup and a [content script](http://code.google.com/chrome/extensions/content_scripts.html).
I want to use jQuery in the popup to manipulate its DOM for presenting data (which I am scraping from the website itself using jQuery injected as a content script). I know I can load jQuery directly in popup.html and use it. However, I wanted to see if I could load jQuery only once in the background page and access it in the popup, rather than loading it each time the popup is opened.
For this, I tried the following in the popup:
var background = chrome.extension.getBackgroundPage();
var $ = background.jQuery;
$("#testID").innerHTML = "testing jQuery";
but it didn't work - `$("#testID")` was undefined. I checked that jQuery was loaded in the background page, and using alternate names for $, e.g. jq, jQuery etc. didn't work either.
Any suggestions on how to make this work?
Received your merge request, but the accounts you linked are the same.
以上就是Using jQuery in Chrome extension: load in background, access in popup的详细内容，更多请关注web前端其它相关文章！