views:

169

answers:

1

In Google Chrome's extension developer section, it says

The HTML pages inside an extension have complete access to each other's DOMs, and they can invoke functions on each other. ... The popup's contents are a web page defined by an HTML file (popup.html). The popup doesn't need to duplicate code that's in the background page (background.html) because the popup can invoke functions on the background page

I've loaded and tested jQuery, and can access DOM elements in background.html with jQuery, but I cannot figure out how to get access to DOM elements in popup.html from background.html.

A: 

Hi Fletcher, can you discuss why you would want to do that? A background page is a page that lives forever for the life time of your extension. While the popup page only lives when you click on the popup.

In my opinion, it should be refactored the other way around, your popup should request something from the background page. You just do this in the popup to access the background page: chrome.extension.getBackgroundPage()

But if you insist, you can use simple communication with extension pages with sendRequest() and onRequest. Perhaps you can use chrome.extension.getViews

Mohamed Mansour
Yesterday as I was investigating I realized the popup seems to be transient; scripts are reloaded each time it is opened. I had assumed it was a persistent object. But now I see any popup state needs to be stored in the background and loaded when the popup is opened.
Fletcher Moore

related questions