我找到了以下 HTML 通知示例,它在 Chrome 和 Firefox 中运行良好。下载并在本地尝试后,它不再在 Chrome 中运行。这是预期的行为(Chrome 由于某种原因阻止本地通知)还是有其他原因导致此功能不起作用?
<!DOCTYPE html>
<html>
<body>
<button onclick="notifyMe()">Notify me!</button>
<script>
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
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
}
</script>
</body>
</html>
根据W3C 规范 http://www.w3.org/TR/notifications/只要文件托管在某个地方,您所拥有的看起来就可以。这是一个不错的通知仓库 https://github.com/girliemac/html5-notifications-webOS-style, with 现场演示 http://girliemac.com/html5-notifications-webOS-style/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)