Advertisement
metalx1000

Basic web notifications and service worker

Oct 1st, 2015
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3.   <script>
  4.     var n;
  5.     navigator.serviceWorker.register('sw.js');
  6.     function showNotification(title,body,icon,tag) {
  7.       Notification.requestPermission(function(result) {
  8.         if (result === 'granted') {
  9.           navigator.serviceWorker.ready.then(function(registration) {
  10.             registration.showNotification(title, {
  11.               body: body,
  12.               icon: icon,
  13.               vibrate: [200, 100, 200, 100, 200, 100, 200]
  14.             });
  15.  
  16.           });
  17.         }
  18.       });
  19.     }
  20.  
  21.   </script>
  22. </head>
  23. <body>
  24.   <button onclick='showNotification("My Title","This is the body","http://filmsbykris.com/v7/img/tux.png","My Tag")'>Click Me</button>
  25.   <br>
  26.   don't forget to:<br>
  27.  touch sw.js
  28. </body>
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement