首页 > 技术文章 > 谷歌chrome浏览器桌面提醒 webkitNotifications

peng14 2014-03-28 13:58 原文

 

 原创:

//点击时开启提醒

$(".message_alert").toggle(function(){
$(".message_alert_tip").html("关闭提醒");
$(".message_alert").find("img").attr("src","public/images/bell_open.png")
initNotificatoin(); //打开浏览器开启桌面提醒询问

},function(){
$(".message_alert_tip").html("开启提醒");
$(".message_alert").find("img").attr("src","public/images/bell_close.png")
alert("要关闭桌面提醒,请设置弹框窗口的右上角按钮");
})

//调用弹出框
systemNotify(icon,title,content) ;
//打开系统消息 
function initNotificatoin(){
if (window.webkitNotifications) {
window.webkitNotifications.requestPermission();
}else{
alert("您的浏览器不支持桌面提醒,请使用谷歌浏览器");
}
}
//系统消息 
function systemNotify(icon,title,content) {
if (window.webkitNotifications) {
if (window.webkitNotifications.checkPermission() == 0) {
var icon="public/images/service.png";
var popup = window.webkitNotifications.createNotification(icon, title, content);
popup.ondisplay = function(event) {
setTimeout(function() {
event.currentTarget.cancel();
}, 5000);
}
popup.show();
} else {
window.webkitNotifications.requestPermission();
return;
}
}
}

推荐阅读