Can you send OS level notification using JavaScript?
Did you know that you can send OS level notification using JavaScript? The Web Notification API let’s you do just that!
To send notifications, you have to follow two steps:
✨ Get permission from the user
🔸 Invoke the Notification.requirePermission() method. This method returns a promise.
🔸 If this is the first time this method is being called, the browser displays a prompt to the user.
🔸 If user has allowed showing notifications for your website, the promise resolves with the value ‘granted’
🔸 If user has denied, then the promise resolves with value ‘denied’
✨ Send the actual notification
🔸 Call new Notification(…) by passing the title along with an optional set of configurations such as the icon, body text, etc
Voila ✨ you have sent your first notification!
👉 Note: without requesting for permission, if you want to check whether the user has provided permission, you can use the Notification.permission method!
#javascript #html #developer #coding #css #programming
[ad_2]
source