var popNotice = function() { if (Notification.permission == "granted") { var notification = new Notification("Hi,", { body: 'Can I add you as a friend? ', icon: '/static/cute.gif' }); notification.onclick = function() { alert('*** has added you as a friend at ' + new Date().toTimeString().split(' ')[0] + '!'); notification.close(); }; } }; if (window.Notification) { if (Notification.permission == "granted") { popNotice (); }else if( Notification.permission != "denied"){ Notification.requestPermission(function (permission) { popNotice (); }); } } else { alert('The browser does not support Notification'); }
The reference address for this article: http://www.zhangxinxu.com/wordpress/?p=5474