浏览器节别的消息推送

function  alertMsg(config){

  var config={

    "username":"小飞机",

    "id":"1000",

    "status":"online/hide",//上线下线

    "sign":"在深邃的编码世界,做一只轻盈的小飞机",

    "avatar":"touxiang.jpg"  

  }

  //判断上线还是下线

  var sxx='';

  if(config['status']=='online'){

    sxx='上线';

  }else if(config['status']=='online'){

    sxx='下线';

  }

  if(!window.Notification){

    alert("浏览器不支持通知!");

  }

  if(window.Notification.permission !="granted"){

    Notification.requestPermission(function(status){

      var permission = Notification.permission;  

    });

  }

  var n new Notification("新消息!",{

    "icon":" "+config['username']+" ",

    "body":"您的好友" +config['username']+ " " +sxx+ " 了 ";

    "lang":"zh-CN",

    //标签识别  相同标签识别,只会打开一个通知窗口

     tag:"linxin",

    //相同的tag,新通知出现时会替换之前的通知

     renotify:true

  });

  n.onshow=function(){

    console.log("显示通知");

    setTimeout(function(){

      n.close()

    },1000*60);

  };

  n.onclick=function(){

    console.log("打开相关视图");

    window.open("");

    n.close();

  };

  n.onclose = function(){

    console.log("通知关闭");

  };

  n.onerror=function(){

    console.log("产生错误");

  }

}

原文地址:https://www.cnblogs.com/xu1115/p/11718512.html