平日学习点滴

 

 使用HTML5中的Notifications API 和 Google Chrome浏览器.

 

 
  
  1.  
  2. function notify() { 
  3. var AUTO_CLOSE_DELAY_SECONDS  = 3; 
  4.     if (window.webkitNotifications) {   
  5.          if (window.webkitNotifications.checkPermission() == 0) {   
  6.                var pop =  window.webkitNotifications.createNotification(icon, title, content); 
  7.          pop.ondisplay = function(event) {   
  8.                    setTimeout(function() {   
  9.                        event.currentTarget.cancel();   
  10.                    }, AUTO_CLOSE_DELAY_SECONDS * 1000);
  11.                }  
  12.      pop.show();  
  13.            } else {   
  14.                window.webkitNotifications.requestPermission();   
  15.                return;   
  16.            }   
  17.      }   
  18.  } 
  19.