0
我正在开发Chrome扩展。nofitication创建的Chrome扩展API不会出现多次
我想在特定条件下显示通知。
我可以显示通知消息一次。
但是,一旦出现通知消息,即使我重装一个网页,它不会再次显示通知消息!
我很困扰这个问题。
请任何人帮助我!
预先感谢:)
manifest.json的
{
"name": "test",
"version": "0.1",
"manifest_version": 2,
"permissions": [
"tabs", "notifications", "http://*/*"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["myscript.js"]
}
]
}
myscript.js
var message = {
text:"hello"
}
chrome.runtime.sendMessage(message, function(response) {
});
backgro und.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var test = chrome.notifications.create(
'notification',{
type: 'basic',
title: "title",
message: request.text,
iconUrl:"icon.png"
},
function(notificationId) {
}
);
chrome.notifications.onClosed.addListener(function (notificationId, byUser){
console.log("this doesn't call as well);
});
谢谢!我在create()方法的回调中调用了clear()方法。这就是为什么它不起作用。现在我有了create()方法之外的clear()方法,它终于可以工作了! – W3Q 2014-09-01 02:41:08