Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
269 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...