Javascript

Browser Notifications from Web Application Using Javascript

Initialize the Browser Notification

For more comfortable to use we need to take user permission to display web notification.

document.addEventListener('DOMContentLoaded', function () { 
 if (Notification.permission !== "granted")
 {
  Notification.requestPermission(); 
 }
});
Push Notification
This function will help you to push notification data, here you have to update icon URL.Also you can pass title, description and Web URL.
if(window.Notification && Notification.permission !== "denied") {
  Notification.requestPermission(function(status) { // status is "granted", if accepted by user
  var n = new Notification('Title', {
   body: 'I am the body text!',
   icon: '/path/to/icon.png' // optional
  });
  }); 
}

Please share and Subscribe to get latest updates and tutorials form Being Idea

Being Idea

Being Idea is a web platform of programming tutorials to make better programming skills and provides Software Development Solutions.

This website uses cookies.