从后台调用页面上的功能 [英] Call functions on pages from background
问题描述
是否可以在页面上调用函数?
例如,我有一个名为help.html的页面,该页面有一个名为help(id)的函数。
我可以调用这个函数并将id传递给它吗?
提前致谢
如果页面已打开并加载,并且您有窗口的引用
对象。确保这两件事情都是真实的一种方法是在准备好的时候,帮助窗口中的代码在背景页上调用一个函数,并将引用传递给它自己。因此,在您的帮助窗口中,您可以使用以下内容:
chrome.extension.getBackgroundPage()。helpWindowLoaded(window);
在您的背景页面上:
函数helpWindowLoaded(helpWindow){
helpWindow.help(id);
}
Is it possible to call function on a page?
For example I have a page called help.html and that page has a function called help(id).
Can I call this function and pass the id to it?
Thanks in advance
You can if the page is opened and loaded, and you have a reference to its window
object. One way to make sure both things are true is to have code on your help window call a function on your background page when it is ready, passing a reference to itself. So on your help window you can have something like:
chrome.extension.getBackgroundPage().helpWindowLoaded(window);
And on your background page:
function helpWindowLoaded(helpWindow) {
helpWindow.help(id);
}
这篇关于从后台调用页面上的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!