嗨,当我在Chrome应用程序的js函数内调用chrome.notifications.create时,会出现错误。 在函数外部可以正常使用,但在函数内部时会出现以下错误:
Uncaught TypeError: Cannot read property 'create' of undefined
这是代码:
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('submit').addEventListener('click', submit);
});
function submit() {
var options = {
type:"basic",
title:"nameVal",
message:"msgVal",
iconUrl:"icon.png",
};
//notification options set
chrome.notifications.create(options,callback);
//notification set
}
function callback() {
console.log("Notification succesfull");
//notification confirmed
}
谢谢,我在js和Chrome应用方面是个新手,所以非常感谢您的帮助 :)
function callback(notificationId) {...}
。如果这不起作用,请尝试从create()函数中删除回调函数引用,使其变成...create(options);
。 - Byren Higgin