binaryBigInt binaryBigInt - 1 year ago 107
Javascript Question

Check if browser notification is available

i am working with browser notifications and because it is not available for every browser i want to check in my JS-code if it is available. I took a look in the mozilla developer section:

They tell me that i should use this code to check whether a browser has notification support or not:

if (!("Notification" in window)) {
alert("This browser does not support system notifications");

Now i copied that code into my website: The notification still works in the browsers where it worked before but it blocks the execution of other code (as it did before the 'check'-code).

For example: in the edge browser i get the console error:

'Notification is undefined'

So what is the preferred method from you to check whether a browser has notification capability?

Answer Source

The following code would check whether the browser is compatible with the web notification API

if ('Notification' in window) {
  // API supported
} else {
  // API not supported
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download