Thursday, July 25, 2013

google chrome desktop notification

ref: http://stackoverflow.com/questions/2271156/chrome-desktop-notification-example

 <script>  
 function notify() {  
  var havePermission = window.webkitNotifications.checkPermission();  
  if (havePermission == 0) {  
   // 0 is PERMISSION_ALLOWED  
   var notification = window.webkitNotifications.createNotification(  
    'http://i.stack.imgur.com/dmHl0.png',  
    'Chrome notification!',  
   'Here is the notification text'  
   );  
   notification.onclick = function () {  
    window.open("http://blog.apis17.info");  
    notification.close();  
   }  
   notification.show();  
  } else {  
    window.webkitNotifications.requestPermission();  
  }  
 }   
 </script>  
 <div style="width: 300px; height: 300px; background: yellow" onclick="notify()">  
 Cick here to notify  
 </div>  

view on jsfiddle

No comments:

Related Posts Plugin for WordPress, Blogger...