Using jQuery in Chrome extension: load in background, access in popup

I am making a [PageAction]( Chrome extension with a popup and a [content script]( 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准