我的Chrome扩展大量使用了webkitNotifications。我想切换到new rich notifications (chrome.notifications),但这些并不是在所有平台上都可用,在我写这篇文章的时候,只有测试版和更高版本。如果丰富的通知不可用,则应该使用webkitNotifications作为后备。因此,我正在寻找实现这一点的最佳解决方案:
if(richNotificationsAvailable())
   chrome.notifications.create(...);
else
   webkitNotifications.createNotification(...).show();我试着检查chrome.notifications.create是否未定义,但它甚至是为Chrome27定义的,在chrome://flags中禁用了丰富的通知。
发布于 2013-05-28 12:45:52
要检测您是否有rich notifications,目前最可靠的方法是测试webkitNotifications.createHTMLNotification的存在-如果该函数是未定义的,则rich notifications已被switched on。
发布于 2014-11-12 09:29:07
只需使用以下代码:
if (webkitNotifications && webkitNotifications.createHTMLNotification) {
    //HTML notifications
} else if (chrome.notifications && chrome.notifications.create) {
    //Rich notifications
}https://stackoverflow.com/questions/16774296
复制相似问题