javascript - HTML 5 通知在 Chrome 中无法在本地运行?

标签 javascript html google-chrome

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

<!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 Specification只要文件托管在某处,您所拥有的看起来就没问题。这是一个不错的 notification repo , 与 live demo .

screenshot

关于javascript - HTML 5 通知在 Chrome 中无法在本地运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24492107/

相关文章:

javascript - Highcharts:更改柱形图的突出显示颜色

javascript - 如何防止用户在文本框中开头输入空格?

javascript - HTML Canvas 通过鼠标平移

javascript - 在不同浏览器中测试javascript兼容性的任何工具或云服务

html - 用于打印的表行 (<tr>) 分页符的防弹解决方案

jquery - Chrome 错误地解释了 JSONP 请求中的相对重定向

javascript - 加载完成后显示 HTML 页面

html - 禁用输入元素的样式 - Chrome 和 Firefox 之间的差异

jQuery 倒计时状态显示在按钮中

html - 如何删除仅在 Chrome 中以不同缩放级别显示的透明图像叠加层上的边框?