允许通知而不单击按钮

我想询问有关通知的信息

现在我有这个通知与“通知我”按钮返回此通知

通知允许

但我仍然使用此按钮来触发推送通知

<button onclick="notifyMe()">Notify me!</button>

这是贾夫脚本函数

 function notifyMe() {


           function AutoRefresh( t ) {

               setTimeout("location.reload(true);", t);

            }

        // Let's check if the browser supports notifications

        if (!("Notification" in window)) {

            alert("This browser does not support desktop notification");

        }


        // Let's check whether notification permissions have already been granted

        else if (Notification.permission === "granted") {

            // If it's okay let's create a notification

            var notification = new Notification("Hi there!");

        }


        // Otherwise, we need to ask the user for permission

        else if (Notification.permission !== "denied") {

            Notification.requestPermission().then(function (permission) {

            // If the user accepts, let's create a notification

            if (permission === "granted") {

                var notification = new Notification("Hi there!");

            }

            });

        }


        }

我想要的是通知自动显示,而无需按钮触发


如何做到这一点?


慕沐林林
浏览 88回答 1
1回答

红糖糍粑

试试这个,jQuery(document).ready(function(){&nbsp; notifyMe();});然后,它将自动触发通知。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript