如何为其他人发送web/桌面通知?

如何为其他人发送web/桌面通知?,web,notifications,send,subscribe,Web,Notifications,Send,Subscribe,我想在关闭我的网站后为我的网站访问者发送桌面通知 我怎样才能让他们订阅? 以及如何为他们发送通知 这个网站做同样的,但我想做我自己的 我看到一些代码,但它只为我发送通知 if (event.target.id === 'button-wn-show-preset') { // Uses the preset parameters } else { // Uses the custom parameters } 似乎您需要类似JavaScript中的onbeforeunload事件处理程

我想在关闭我的网站后为我的网站访问者发送桌面通知

我怎样才能让他们订阅? 以及如何为他们发送通知

这个网站做同样的,但我想做我自己的

我看到一些代码,但它只为我发送通知

if (event.target.id === 'button-wn-show-preset') {
  // Uses the preset parameters
} else {
  // Uses the custom parameters
}

似乎您需要类似JavaScript中的
onbeforeunload
事件处理程序。当用户离开页面时,会出现JS弹出警告。请查看有关用法的详细信息

上面链接中的示例:

<!DOCTYPE html>
<html>
<body onbeforeunload="notifyMe()">


<script>
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
    if (Notification.permission !== "granted")
        Notification.requestPermission();
});

function notifyMe() {
    if (!Notification) {
        alert('Desktop notifications not available in your browser. Try Chromium.'); 
        return;
    }

    if (Notification.permission !== "granted")
        Notification.requestPermission();
    else {
        var notification = new Notification('Notification title', {
        icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
        body: "Hey there! You've been notified!",
    });

    notification.onclick = function () {
        window.open("http://stackoverflow.com/a/13328397/1269037");      
    };
  }
}
</script>

</body>
</html>

//请求页面加载权限
document.addEventListener('DOMContentLoaded',函数(){
if(Notification.permission!=“已授予”)
Notification.requestPermission();
});
函数notifyMe(){
如果(!通知){
警报('您的浏览器中没有桌面通知。请尝试使用Chromium');
返回;
}
if(Notification.permission!=“已授予”)
Notification.requestPermission();
否则{
var通知=新通知(“通知标题”{
图标:'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
身体:“嘿!已经通知你了!”,
});
notification.onclick=函数(){
窗口打开(“http://stackoverflow.com/a/13328397/1269037");      
};
}
}

您的问题太广泛,无法回答。如果你真的想让你自己的通知系统,我建议你寻找一个教程,并开始建立它。然后就您遇到的问题提出具体问题,提供代码示例,并解释您试图实现的目标以及为什么您认为它不起作用。谢谢您的评论,但不是我想要的,而是我想要的桌面通知。这里是一个示例,我编辑了我的答案,以使用jsbin中的代码。当用户从页面导航时,它应该可以推送通知。