Webkit 通知 requestPermission 功能不起作用 [英] Webkit notifications requestPermission function doesn't work

查看:33
本文介绍了Webkit 通知 requestPermission 功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上实现对 WebKit 的本机桌面通知的支持.当我尝试请求用户许可使用通知时,绝对没有任何反应.例如,以下 HTML 不会提示 Chrome 请求我的许可:

I am trying to implement support for WebKit's native desktop notifications on my site. When I try to ask for user's permission to use the notifications, absolutely nothing happens. For example, the following HTML does not prompt Chrome to ask me for permission:

<html lang="en">
<head></head>

<body>
    <h1>Testing</h1>
    <script>
        window.webkitNotifications.requestPermission();
    </script>
</body>
</html>

我知道我的 Chrome 版本没有问题,因为其他网站(例如 http://www.html5rocks.com/tutorials/notifications/quick/) 工作得很好:我可以看到提示和后续通知.

I know that there is no problem with my version of Chrome because other sites (e.g. http://www.html5rocks.com/tutorials/notifications/quick/) work perfectly fine: I can see both the prompt and the subsequent notifications.

推荐答案

chromium api 文档.您只能将其称为对用户手势/动作(鼠标点击等)的反馈.

Check the specification at chromium api docs. You can call it only as a feedback to user gesture/action - mouse click etc.

requestPermission 请求用户代理请求用户许可显示来自脚本的通知.这个方法只能被调用处理用户手势时;在其他情况不会有影响.此方法是异步的.回调中提供的函数将当用户响应时调用到许可请求.如果当前权限级别是PERMISSION_DENIED,用户代理可以不采取任何行动来回应请求权限.

requestPermission Requests that the user agent ask the user for permission to show notifications from scripts. This method should only be called while handling a user gesture; in other circumstances it will have no effect. This method is asynchronous. The function provided in callback will be invoked when the user has responded to the permission request. If the current permission level is PERMISSION_DENIED, the user agent may take no action in response to requestPermission.

更新 2014-10-01:在 Chrome 37 中,删除了用户手势要求.现在应该可以随时请求显示通知的权限.如果您还希望针对旧版本的 Chrome(例如在公司环境中),您可能需要继续依赖用户手势事件.

UPDATE 2014-10-01: In Chrome 37, the user gesture requirement was removed. It should now be possible to request permission to display notifications at any moment. If you wish to target older versions of Chrome as well (eg. in a corporate environment), you'll probably need to continue relying on user gesture events.

这篇关于Webkit 通知 requestPermission 功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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