我真的不知道的JQuery因此Im沒有幫助那裏,但認爲Id指出的是,它似乎工作JS方式....
manifest.json的
{
"name": "TEST - Background to PopUp Event Triggering",
"version": "1.0",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_title": "TEST - Background to PopUp Event Triggering",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"]
},
"manifest_version" : 2
}
popup.html
<!doctype html>
<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
popup.js
個
var backgroundPage = chrome.extension.getBackgroundPage();
backgroundPage.document.addEventListener('myCustomEvent', function(e) {
document.write(e.args + '\n');
})
background.js
var customEvent = document.createEvent('Event');
customEvent.initEvent('myCustomEvent', true, true);
setInterval(function() {
customEvent.args=["bunyips","smell"];
document.dispatchEvent(customEvent);
}, 3000);
你爲什麼不使用專用[消息傳遞(http://code.google.com/chrome/extensions/messaging.html)模塊?通過簡單的添加,您也可以支持事件。 – pimvdb 2012-07-27 18:54:03
1. jQuery是在彈出的*和*背景頁面中加載的嗎? 2.任何內嵌JavaScript(如果是,請閱讀[CSP](http://code.google.com/chrome/extensions/contentSecurityPolicy.html))。 3.你是否在觸發前約束事件? 3.爲什麼在使用函數時可以以非複雜的方式完成相同的事件? 'chrome.extension.getBackgroundPage()。customMethod();'和/或['chrome.extension.getViews()'](http://code.google.com/chrome/extensions/extension.html#method-getViews )。 – 2012-07-27 19:59:40
其實,@ pimvdb,這正是我所做的。 – 2012-07-27 20:51:39