允许通知而不点击按钮

Allow Notification without clicking button

我想问一下通知

现在我收到带有 "Notify Me" 按钮的通知 return 此通知

Notification allow

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

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

这是 javscript 函数

 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!");
            }
            });
        }

        }

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

怎么做?

试试这个,

jQuery(document).ready(function(){
  notifyMe();
});

然后,它会自动触发通知。