Chrome Extension notifications【谷歌浏览器扩展之弹窗通知】

来源:互联网 发布:淘宝上的小样是真是假? 编辑:程序博客网 时间:2024/05/29 17:30

       起初为方便快速使用的是 alert ,后优化时发现并使用 notifications API 来代替。

        使用 chrome.notifications API 须先配置 manifest 文件中的 permissions :

"permissions": ["notifications","downloads","storage"]

调用示例:

chrome.notifications.getPermissionLevel(function(level){//获取用户是否为当前应用或应用启用通知(permissions中已配置可直接调用notifications)if( level == 'granted' ){//发出通知, type 默认为 basicchrome.notifications.create('notify_alert1', // notifyId{type: "basic", iconUrl: "icon-48.png", title: "更新完成!", message: "请查看页面数据是否已更新。"}, function(notifyId){//不用移除该消息,否者不会显示// chrome.notifications.clear(notifyId, function(){ });});}else{//...alert('更新完成!')}});


阅读全文
0 0