首页 > 其他 > 详细

showMsgNotification

时间:2015-04-24 16:14:23      阅读:229      评论:0      收藏:0      [点我收藏+]
function showMsgNotification(title, msg){
 var Notification = window.Notification || window.mozNotification || window.webkitNotification;
 
 if (Notification && Notification.permission === "granted") {
  var instance = new Notification(
   title, {
    body: msg,
    icon: "image_url"
   }
  );
 
  instance.onclick = function () {
   // Something to do
  };
  instance.onerror = function () {
   // Something to do
  };
  instance.onshow = function () {
   // Something to do
   // console.log(instance.close);
   setTimeout(instance.close, 3000);
  };
  instance.onclose = function () {
   // Something to do
  };
 }else if (Notification && Notification.permission !== "denied") {
  Notification.requestPermission(function (status) {
   if (Notification.permission !== status) {
    Notification.permission = status;
   }
   // If the user said okay
   if (status === "granted") {
    var instance = new Notification(
     title, {
      body: msg,
      icon: "image_url"
     }
    );
   
    instance.onclick = function () {
     // Something to do
    };
    instance.onerror = function () {
     // Something to do
    };
    instance.onshow = function () {
     // Something to do
     setTimeout(instance.close, 3000);
    };
    instance.onclose = function () {
     // Something to do
    };
 
   }else {
    return false
   }
  });
 }else{
  if(!window.webkitNotifications){
   alert("您的浏览器不支持Notification桌面通知!");
  }
  return false;
 }
 
}
showMsgNotification(‘ddd‘,‘ddd‘);

 

showMsgNotification

原文:http://www.cnblogs.com/vi2014/p/4453533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!