Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What ways are out there to display a desktop notification from a web app?

What I would like to do is show a toaster like notification preferably but any method of "pushing" updates to the desktop is interesting.

Thanks

like image 984
reshefm Avatar asked May 23 '11 04:05

reshefm


People also ask

How do desktop notifications work?

Web push notifications (also known as browser push notifications) are actionable messages sent to a visitor's device from a website via a browser. These messages are contextual, timely, personalized, and best used to engage, re-engage, and retain website visitors.


2 Answers

Below is a working example of desktop notifications for Chrome, Firefox, Opera and Safari, copied from Chrome desktop notification example.
Try it live on JSBin.

// 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("https://stackoverflow.com/a/13328397/1269037");           };    }  } 
<button onclick="notifyMe()">Notify me!</button> 

More information about how this works in my answer to Chrome desktop notification example.

like image 84
Dan Dascalescu Avatar answered Oct 11 '22 13:10

Dan Dascalescu


On Chrome, you can achieve something like this using Desktop notification. See Chrome desktop notification example for example.

If your users have growl installed on their machine you should check out growl developer page

like image 30
Jay Sidri Avatar answered Oct 11 '22 14:10

Jay Sidri