Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从Chrome创建桌面通知?_Javascript_Google Chrome_Notifications - Fatal编程技术网

Javascript 如何从Chrome创建桌面通知?

Javascript 如何从Chrome创建桌面通知?,javascript,google-chrome,notifications,Javascript,Google Chrome,Notifications,我注意到在StackExchange聊天中,我现在可以启用桌面通知(我也在Gmail和谷歌音乐中使用)。现在我已经决定,我希望能够在我的网站上做到这一点。我在谷歌上搜索了一下,但只找到了。如何在我自己的站点中进行桌面通知 编辑 在Chrome控制台中,我找到了函数webkitNotifications.requestPermission(),但调用它没有任何作用。我希望它会显示Chrome的顶部栏,询问“您想为其启用桌面通知吗?”http://...?“有一个漂亮的房间。希望这有帮助 仅供参考,

我注意到在StackExchange聊天中,我现在可以启用桌面通知(我也在Gmail和谷歌音乐中使用)。现在我已经决定,我希望能够在我的网站上做到这一点。我在谷歌上搜索了一下,但只找到了。如何在我自己的站点中进行桌面通知

编辑

在Chrome控制台中,我找到了函数
webkitNotifications.requestPermission()
,但调用它没有任何作用。我希望它会显示Chrome的顶部栏,询问“您想为其启用桌面通知吗?”http://...?“

有一个漂亮的房间。希望这有帮助

仅供参考,
webkitNotifications.requestPermission()
调用它时没有执行任何操作的原因是

仅当在中处理用户手势时才应调用此方法 在其他情况下,它将不起作用

如中所述。因此,您可能需要在用户手势(如鼠标单击)中实现此方法,以使其有效:

<script>
function requestNotificationPermission()
{
    window.webkitNotifications.requestPermission();
}
</script>

<a onclick="requestNotificationPermission(); return false;" href="#">Request notifications permission</a>

函数requestNotificationPermission()
{
window.webkitNotifications.requestPermission();
}
有一个很好的方法。希望这有帮助

仅供参考,
webkitNotifications.requestPermission()
调用它时没有执行任何操作的原因是

仅当在中处理用户手势时才应调用此方法 在其他情况下,它将不起作用

如中所述。因此,您可能需要在用户手势(如鼠标单击)中实现此方法,以使其有效:

<script>
function requestNotificationPermission()
{
    window.webkitNotifications.requestPermission();
}
</script>

<a onclick="requestNotificationPermission(); return false;" href="#">Request notifications permission</a>

函数requestNotificationPermission()
{
window.webkitNotifications.requestPermission();
}