ウェブサイトを閉じた後、ウェブサイトの訪問者にデスクトップ通知を送信したい
どうすれば購読させることができますか? そしてそれらすべてに通知を送信する方法
このウェブサイトは同じになります jeapie.com、でも自分で作りたい
私はいくつかのコードを見ましたが、それは私だけに通知を送信します
if (event.target.id === "button-wn-show-preset") {
// Uses the preset parameters
} else {
// Uses the custom parameters
}
回答:
回答№1は0あなたはのようなものが欲しいようです onbeforeunload
JavaScriptのイベントハンドラー。ユーザーがページから移動すると、JSポップアップ警告が表示されます。をチェックしてください W3リファレンス 使用のため。
上記のリンクからの例:
<!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>