2016-11-23 167 views
-2

我想检测对HTML5 Notifications API的支持,而不会引发错误。我宁愿能够同步检测支持,尽管使用承诺或回调会很好。检测支持通知

回答

2

我觉得你要找的是window.Notification。

if (window.Notification) { 
 
    alert('support'); 
 
} else { 
 
    alert('no support'); 
 
}

这里如果你想知道的浏览器支持的最新列表: http://caniuse.com/#search=Notification

+1

我不知道你需要的承诺。下面是一个例子,让你开始如何做到这一点,没有承诺回退。我不主张使用插件,但网站上的示例代码显示了如何备用。 https://blog.brunoscopelliti.com/a-fallback-plugin-for-html5-web-notifications/ – easement