Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // simple function to create a notification
- function notify(bodyTxt) {
- new Notification('Notification Title', {
- body: bodyTxt,
- icon: '/img/favicon.png'
- });
- };
- switch(Notification.permission) {
- // user previously denied permission
- case "denied":
- window.alert('You denied permission. Please change your browser settings for this page to view notifications');
- // user already has accepted permission
- case "granted":
- notify('You have already granted permission');
- break;
- // should be "default", but catch all anyways
- default:
- Notification.requestPermission((status) => {
- if (status === "granted") notify('Thank you for granting permission');
- });
- }
Add Comment
Please, Sign In to add comment