<html lang="en"> <head></head> <body> <h1>Testing</h1> <script> window.webkitNotifications.requestPermission(); </script> </body> </html>
我知道我的Chrome版本没有问题,因为其他网站(例如http://www.html5rocks.com/tutorials/notifications/quick/)的工作完全正常:我可以看到提示和后续通知。
解决方法
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:在Chrome 37,the user gesture requirement was removed.现在应该可以请求权限显示通知在任何时刻。如果您还希望定位旧版Chrome(例如在公司环境中),您可能需要继续依赖用户手势事件。