开发者

call popup.html javascript function from background page

开发者_如何学CHow to call javascript function in popup.html from background page ( in chrome extensions)?


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.


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();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜