js html5推送 实例

<!DOCTYPE html>
  <html>
  <head>
  <title>Simple Webkit notification example</title>
  </head>
   
  <h2>设置权限</h2>
  <button id="request">允许</button>
  <h2>显示消息</h2>
  <button id="show">显示消息</button>
   
  <script type="text/javascript">
   
   
  document.getElementById('request').addEventListener('click', function() {
  window.webkitNotifications.requestPermission();
  }, false);
   
   
  document.getElementById('show').addEventListener('click', function() {
  showNotification();
  }, false);
   
  function showNotification() {
  // only show if we've got the correct permissions
  if (window.webkitNotifications.checkPermission() === 0) {
  // note the show()
  window.webkitNotifications.createNotification('http://m.poco.cn/mobile/images/app_icon-114x114.png', '欢迎进入POCO世界', 'POCO世界!').show();
  }
  }
  </script>
  </html>
posted @ 2014-04-09 21:37  晕菜一员  阅读(226)  评论(0编辑  收藏  举报