cmac cmac - 1 year ago 86
Javascript Question

How to check if notifications is already allowed by user in google chrome?

I have a modal that pops up first asking if the user wants to receive special offers, if they click yes, then I pull in the code for push notifications so that they can allow notifications. If they already allowed notifications I don't want the modal to pop up. I am looking for a way to check if notifications has already been allowed by the user, using google chrome.

Answer Source

Check the permission property of the Notification object:

if (Notification.permission !== "granted") {
    // ask for permission
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download