2

How to call javascript function in popup.html from background page ( in chrome extensions)?

3 Answers 3

3

Unfortunately it is not possible to get a direct reference to the popup page, the main reason is that the page might not be open when you try and call it.

You have to use message passing to pass a message between popups and background pages.

I would ask is there a specific need to have the function in the popup and not have it re-factored into a separate shared file.

Sign up to request clarification or add additional context in comments.

2 Comments

I wanto modify popup depending of the content of the page.
I would place the logic in the background page, and in the onload event on your popups document>body get the information from the background page. You can also change the physical background page by using: setPopup code.google.com/chrome/extensions/trunk/…
2

Would be best to place that functionality in a Background page instead and within your popup you can do:

var bkg = chrome.extension.getBackgroundPage()
bkg.someBackgroundPageFunction();

Comments

1

Thanks for the contributions. I found this reference which solved the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.