I am working with the HTML5 desktop notification. it's working well and give me proper output as per my requirements. Now, I want to display that notification until user close that notification manually how it.s possible my code is as following.
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
else if (Notification.permission === "granted") {
var options = {
body: "due to your inactive response timer is stoped automatically. Start your timer again.",
dir : "ltr"
};
var notification = new Notification("Your timer is stop",options);
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}
if (permission === "granted") {
var options = {
body: "due to your inactive response timer is stoped automatically. Start your timer again.",
dir : "ltr"
};
var notification = new Notification("Your timer is stop",options);
}
});
}
}
close() Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. The close() method of the Notification interface is used to close/remove a previously displayed notification.
Browser notifications are simply notifications that can be sent by web applications and websites. The messages are received by the user's browser client. Browser notifications can be sent even when the particular website is not actively in use.
It stays indefinitely on Chrome. There's a bug in Firefox which auto-closes it after 4 seconds: https://bugzilla.mozilla.org/show_bug.cgi?id=875114
Try with "requireInteraction" in the option, will work in firefox and chrome both. The code is:
var options = {
body: "due to your inactive response timer is stoped automatically. Start your timer again.",
dir : "ltr",
requireInteraction: true
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With