首页 > 其他 > 详细

浏览器节别的消息推送

时间:2019-10-22 12:07:24      阅读:81      评论:0      收藏:0      [点我收藏+]

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

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