<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>弹出提示</title>
</head>
<body>
<script type="text/JavaScript">
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}

else if (Notification.permission === "granted") {
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!");
}
});
}

// At last, if the user already denied any notification, and you
// want to be respectful there is no need to bother him any more.
}
</script>
<button onclick="notifyMe()">Notify me!</button>
</body>
</html>

整理自:http://url.cn/NGixjh
http://www.cnblogs.com/lxshanye/p/3560188.html

W3C标准的Notification

/**
* 显示notification,by Notification
* @return {[type]}
*/
var _showNotificationByW3C = function(){
window.indexForNotify = window.indexForNotify ? ++window.indexForNotify : 1;
var notify = new Notification(
"Alien: " + (new Date()).toUTCString(),
{
iconUrl : Session.staticDomain + "/img/alien20.jpg",
tag : 'tag_by_alien',
body : "你好,这个是通过Notification来创建的,这的名字叫:Demo"
+ window.indexForNotify + ","
+ "你可以通过它来做一些很炫的桌面提醒应用!这个API还很不成熟,"
+ "连个icon都显示不出来!!!它哭着对我说,API都是骗人的!"
});
notify.onerror = function(event){
console.log("error事件被触发:",event);
};
notify.onshow = function(event){
console.log("show事件被触发:",event);
};
notify.ondisplay = function(event){
console.log("display事件被触发:",event);
};
notify.onclick = function(event){
console.log("click事件被触发:",event);
notify.cancel();
};
notify.onclose = function(event){
console.log("close事件被触发:",event);
};
notify.show();
};

摘自: http://www.baidufe.com/item/3690af56196c85bf66a0.html

Related Posts: Firefox-Chrome-html5弹出桌面通知 :