web通知

<html>
<head>
    <title>桌面通知</title>
    <meta name="description" content="实战Chrome浏览器桌面通知" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
    <script type='text/javascript'>
 
    //granted  允许  denied 拒绝  undefined  未定义  default 用户不操作
    function getStatus()
    {
 
        return Notification.permission;
 
 
    }
 
 
    function init() {
      if (!("Notification" in window)){
          alert("您当前浏览器不支持该功能!\n建议使用猎豹、360等浏览器使用此功能");
          $("#zmtz").removeAttr("checked");
      }
      else {
          //申请授权
          if (Notification.permission == null || Notification.permission == undefined)
              window.webkitNotifications.requestPermission();
          else if (Notification.permission !== 'denied') {
              Notification.requestPermission(function (permission) {
                  if (!('permission' in Notification))
                      Notification.permission = permission;
              });
          }
          $("#zmtz").attr("checked","checked");
      }
}
 
 
 
    function send(title,theBody,theIcon)
    {
 
    var options = {
      body: theBody,
      icon: theIcon
    }
 
 
    if (!("Notification" in window)) {
 
    return ;
  }
 
 
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification(title,options);
  }
 
  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== 'denied') {
    Notification.requestPermission(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification(title,options);
      }
    });
  }
 
 
 
 
    }
    </script>
 
</head>
<body>
 
 
 
 
 
<div>
<input type="button" value="开启" onclick="javascript:init()">
通知内容:<input type="button" value="发喊单"  onclick="javascript:send('您有一条新喊单','详细信息','1.png')">
<input type="button" value="获取状态" onclick="javascript:alert(getStatus())">
</div>
 
 
 
 
 
 
 
</body>
</html>

 

转载于:https://www.cnblogs.com/aliblogs/p/5493826.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值