Javascript 在chrome上激活chrome.notifications对象
我想尝试在chrome上使用Javascript 在chrome上激活chrome.notifications对象,javascript,api,google-chrome,notifications,Javascript,Api,Google Chrome,Notifications,我想尝试在chrome上使用chrome.notificationsapi(使用Windows和Chrome40+,因此该api是受支持的)。唯一的问题是,在尝试使用时,对象根本不存在。chrome.notifications的类型未定义,显然,如果我尝试使用chrome.notifications.create,我会收到一个错误“无法读取未定义的属性create” 问题是,我已经激活了通知,我在我的android手机上使用了pushbullet,它使用了丰富的通知功能,并且工作得非常完美 那么
chrome.notifications
api(使用Windows和Chrome40+,因此该api是受支持的)。唯一的问题是,在尝试使用时,对象根本不存在。chrome.notifications
的类型未定义,显然,如果我尝试使用chrome.notifications.create
,我会收到一个错误“无法读取未定义的属性create”
问题是,我已经激活了通知,我在我的android手机上使用了pushbullet,它使用了丰富的通知功能,并且工作得非常完美
那么chrome.notifications
是否为chrome应用程序保留
非常感谢。我认为
chrome.notifications
只是chrome插件,但您可以使用
这是一项实验性技术由于这项技术的规范还没有稳定下来,请检查是否有合适的前缀可在各种浏览器中使用。还请注意,随着规范的变化,实验技术的语法和行为在未来版本的浏览器中可能会发生变化
是的,我实际上已经为它开发了一个迷你库(github.com/jsmrcaga/miniNotif),但我想在不使用插件的情况下从web发出丰富的通知。可惜你不能。非常感谢!
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user already denied any notification, and you
// want to be respectful there is no need to bother them any more.
}