0
由于某种奇怪的原因,我似乎无法从popup.html javascript调用背景页面功能。 (JS不是内联的,而是一个单独的脚本)。从弹出页面调用背景页面功能不工作(扩展名为Chrome)
popup.js(从popup.html引用的脚本)
var bgPage = chrome.extension.getBackgroundPage();
// debugger shows here that bgPage is indeed != null,
// also - bgPage.myFunc prints my function, yay!
// However, calling the function does nothing, and quits
// the debugging without any exception
bgPage.myFunc();
background.js
function myFunc() {
console.log(1); // never happens
}
这是为什么? 这听起来与我有关的一些安全策略...不允许我调用bg函数...也许?
btw:试过的消息也过去了,也没有工作。
作为评论,'chrome.extension.getBackgrounPage'应该被视为弃用,以支持'chrome.runtime.getBackgroundPage'。前者不适用于事件页面。 – Xan 2014-09-04 10:02:49
@Xan'chrome.extension.getBackgroundPage' is * not * deprecated。如果您有意识地在事件页面上使用背景页面(例如,因为您使用的是长时间运行的'WebSocket'),则c.e.gBP将始终按预期工作。 – 2014-09-04 10:13:39