Call popup.html javascript function from background page

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

+2


source to share


3 answers


Unfortunately, it is not possible to get a direct link to the popup page, the main reason is that the page may not open when you try to call it.

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



I would ask if there is a definite need to have the function in the popup and not reinstall it in a separate shared file.

+3


source


Your best bet is to put this functionality in a Background page and inside your popup, which you can do:



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

      

+2


source


Thanks for the input. I found this link which solved the problem.

+1


source







All Articles