检测Chrome中的Rich Notifications是否可用 [英] Detect if Rich Notifications in Chrome are available

查看:288
本文介绍了检测Chrome中的Rich Notifications是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Chrome扩展程序大量使用webkitNotifications。我想切换到新的丰富通知(chrome.notifications),但是目前尚未在所有平台上提供,并且只能在测试版频道中编写和更新。如果丰富的通知不可用,则应使用webkitNotifications作为回退。因此,我正在寻找实现此目标的最佳解决方案:

My Chrome extension makes heavy use of webkitNotifications. I want to switch to the new rich notifications (chrome.notifications) but those aren't available on all platforms yet and at the moment of writing only in the beta channel and up. If the rich notifications aren't available webkitNotifications should be used as fallback. Thus I'm looking for the best solution to implement this:

if(richNotificationsAvailable())
   chrome.notifications.create(...);
else
   webkitNotifications.createNotification(...).show();

我试着检查 chrome.notifications.create 用于未定义,但它甚至为Chrome 27定义,其中禁用了丰富的通知 chrome:// flags

推荐答案

code> rich notifications ,最可靠的方法是测试 webkitNotifications.createHTMLNotification 是否存在 - 如果该函数未定义,那么丰富的通知已被开启

To detect if you have rich notifications, the most reliable way is currently to test for the existence of webkitNotifications.createHTMLNotification - if that function is undefined, then rich notifications have been switched on.

这篇关于检测Chrome中的Rich Notifications是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆