gpt4 book ai didi

javascript - 为什么此桌面通知代码在 Chrome 中不起作用

转载 作者:行者123 更新时间:2023-11-30 10:44:32 25 4
gpt4 key购买 nike

我正在使用下面的代码来显示通知。但它不起作用。请帮我解决这个问题

 $(document).ready(function(){
if (window.webkitNotifications.checkPermission() == 0) {
var popup = window.webkitNotifications.createNotification
("", "Notifier", "Properties will be displayed like this");
popup.show();
}
});

使用上面的代码我看不到任何通知。

最佳答案

我看到您正在使用 $(document).ready(),也许您也在使用那种东西来请求许可。这是无法完成的,必须在用户操作(例如单击按钮)时请求:

However, it's very important to remember that the requestPermission method only works in event handlers triggered by a user action, like mouse or keyboard events, in order to avoid unsolicited infobars. In this case, the user action is the click on the button with id "show_button".

http://www.html5rocks.com/en/tutorials/notifications/quick/#toc-step3

仔细检查您的 window.webkitNotifications.checkPermission() 值,您可能会发现它实际上不是 0,除非您在用户操作的条件下请求。

关于javascript - 为什么此桌面通知代码在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com