平日学习点滴
使用HTML5中的Notifications API 和 Google Chrome浏览器.
- function notify() {
- var AUTO_CLOSE_DELAY_SECONDS = 3;
- if (window.webkitNotifications) {
- if (window.webkitNotifications.checkPermission() == 0) {
- var pop = window.webkitNotifications.createNotification(icon, title, content);
- pop.ondisplay = function(event) {
- setTimeout(function() {
- event.currentTarget.cancel();
- }, AUTO_CLOSE_DELAY_SECONDS * 1000);
- }
- pop.show();
- } else {
- window.webkitNotifications.requestPermission();
- return;
- }
- }
- }
转载于:https://blog.51cto.com/snowdream/1152681