HTML 5通知无法在chrome本地工作吗? [英] HTML 5 Notifications are not working locally in chrome?

查看:79
本文介绍了HTML 5通知无法在chrome本地工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了以下HTML通知示例,它在Chrome和Firefox中运行良好.下载并在本地尝试后,它不再适用于Chrome.这是预期的行为(Chrome出于某种原因阻止了在本地进行通知),还是有其他原因导致其不起作用?

I have found the following example for HTML notifications and it worked fine in Chrome and Firefox. After downloading it and trying it locally it does not work in Chrome anymore. Is this expected behaviour (Chrome preventing notifications locally for some reason) or is there any other reason why this is not working?

<!DOCTYPE html>
<html>

    <body>

        <button onclick="notifyMe()">Notify me!</button>

        <script>
        function notifyMe() {
          // Let's check if the browser supports notifications
          if (!("Notification" in window)) {
            alert("This browser does not support desktop notification");
          }

          // Let's check if the user is okay to get some notification
          else if (Notification.permission === "granted") {
            // If it's okay let's create a notification
            var notification = new Notification("Hi there!");
          }

          // Otherwise, we need to ask the user for permission
          // Note, Chrome does not implement the permission static property
          // So we have to check for NOT 'denied' instead of 'default'
          else if (Notification.permission !== 'denied') {
            Notification.requestPermission(function (permission) {

              // Whatever the user answers, we make sure we store the information
              if(!('permission' in Notification)) {
                Notification.permission = permission;
              }

              // If the user is okay, let's create a notification
              if (permission === "granted") {
                var notification = new Notification("Hi there!");
              }
            });
          }

        }
        </script>

    </body>
</html>

推荐答案

根据 W3C规范只要文件托管在某个地方,您的内容就可以.这是一个很好的通知存储库,其中带有

According to the W3C Specification what you have looks ok as long as the file is hosted somewhere. Here is a nice notification repo, with live demo.

这篇关于HTML 5通知无法在chrome本地工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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