Guest User

Untitled

a guest
Nov 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // simple function to create a notification
  2. function notify(bodyTxt) {
  3. new Notification('Notification Title', {
  4. body: bodyTxt,
  5. icon: '/img/favicon.png'
  6. });
  7. };
  8.  
  9. switch(Notification.permission) {
  10. // user previously denied permission
  11. case "denied":
  12. window.alert('You denied permission. Please change your browser settings for this page to view notifications');
  13. // user already has accepted permission
  14. case "granted":
  15. notify('You have already granted permission');
  16. break;
  17. // should be "default", but catch all anyways
  18. default:
  19. Notification.requestPermission((status) => {
  20. if (status === "granted") notify('Thank you for granting permission');
  21. });
  22. }
Add Comment
Please, Sign In to add comment