var notification = new Notification('来消息了', { body: '可以加你为好友吗?', icon: 'http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg', }); notification.onclick = function() { window....
桌面提示信息Notify me!function notifyMe() { // 先检查浏览器是否支持 if (!("Notification" in window)) { alert("This browser does not support desktop notification"); } // 检查用户是否同意接受通知 else if (Notification.permission === "granted") { var notification = new Notification('来消息了', { body: '可以加你为好友吗?', icon: 'http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg', }); notification.onclick = function() { window.focus();//打开对应的页面 notification.close();//关闭提示信息 }; //定时关闭 notification.onshow = function () {//定时关闭 setTimeout(notification.close.bind(notification), 3000); } } // 否则我们需要向用户获取权限 else if (Notification.permission !== 'denied') { Notification.requestPermission(function (permission) { // 如果用户同意,就可以向他们发送通知 if (permission === "granted") { var notification = new Notification('111', { body: '第一次点击同意提示,显示本条信息。' }); } }); } }
就是