Notification.requestPermission(function(status) {
//default 用户没有接收或拒绝授权请求 不能显示通知
//granted 用户接受授权请求 允许显示通知
//denied 用户拒绝授权请求 不允许显示通知
console.log(‘permission: ‘ + status);
if (Notification.permission === ‘granted‘) {
var n = new Notification("推送通知", {
icon: ‘https://www.baidu.com/img/bd_logo1.png‘,
body: ‘点我带你去百度,60s后消失‘
});
n.onshow = function() {
setTimeout(function() {
n.close();
}, 60000);
};
n.onclick = function() {
window.open(‘http://www.baidu.com‘);
n.close();
};
n.onerror = function() {
console.log(‘error‘);
};
n.onclose = function() {
console.log(‘close‘);
};
}
});