码迷,mamicode.com
首页 > 其他好文 > 详细

showMsgNotification

时间:2015-04-24 16:16:26      阅读:143      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!