Prešiel som toľko webových stránok, ale neviem nájsť správnu odpoveď, môžete mi s tým pomôcť. Chcem vedieť, ako je možné vytvoriť upozornenie na web (nie pre aplikáciu pre Android, ale iba pre webové stránky)?
odpovede:
0 pre odpoveď č. 1Môžete jednoducho pridať tento riadok kódu:
var myNotification = new Notification(title, options);
Dávam vám lepší príklad, musíte sa pýtať používateľa, či môžete pridať upozornenia:
function notifyMe() {
// Let"s check if the browser supports notifications
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}
// Let"s check whether notification permissions have alredy 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.permission === "default") {
Notification.requestPermission(function (permission) {
// If the user accepts, let"s create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
Môžete sa obrátiť na Dokumentácia MDN a Špecifikácia MDN.