Web 通知在 chrome 上不起作用,但在 Firefox 和 microsoft edge 上运行良好 [英] Web notifications is not working on chrome, but it's working fine on firefox and microsoft edge

查看:58
本文介绍了Web 通知在 chrome 上不起作用,但在 Firefox 和 microsoft edge 上运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作网络通知,这在 Firefox 和 microsoft edge 上运行良好.即使它在 safari 上运行良好.但它不想在 chrome 上工作.它没有显示错误.这是我的代码:

I am trying to make web notification, which is worked fine on firefox and microsoft edge. even it worked fine on safari. but it does not want to work on chrome. and it shows no error. this is my code:

    <script>
    window.setInterval(function(){notifyMe();}, 5000);
    function notifyMe() {
      if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
      } else if (Notification.permission === "granted") {
          var data = []
          data['title'] = "notification's title";
          data['body'] = "notification's body";
          var notification = new Notification(data['title'], {
            'body': data['body']
          });
          notification.onclick = function(event) {
            window.open('https://www.example.com/', '_blank');
          }
      } else if (Notification.permission !== "denied") {
        Notification.requestPermission().then(function (permission) {
          if (permission === "granted") {
            var notification = new Notification("really");
          }
        });
      }
    }
</script>

推荐答案

您的网站是否使用 https:// 提供服务 - 因为 Chrome 已弃用不安全的通知 API(例如 http://) 起源

Is your website served using https:// - because Chrome has deprecated Notifications API on insecure (e.g. http://) origins

否则,您的代码在 Chrome 中运行良好

Otherwise, your code works just fine in Chrome

这篇关于Web 通知在 chrome 上不起作用,但在 Firefox 和 microsoft edge 上运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆