您的位置:首页 > 其它

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

2017-09-04 10:37 896 查看
       起初为方便快速使用的是 alert ,后优化时发现并使用 notifications API 来代替。

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

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


调用示例:

chrome.notifications.getPermissionLevel(function(level){
//获取用户是否为当前应用或应用启用通知(permissions中已配置可直接调用notifications)
if( level == 'granted' ){
//发出通知, type 默认为 basic
chrome.notifications.create(
'notify_alert1', // notifyId
{type: "basic", iconUrl: "icon-48.png", title: "更新完成!", message: "请查看页面数据是否已更新。"},
function(notifyId){
//不用移除该消息,否者不会显示
// chrome.notifications.clear(notifyId, function(){ });
}
);
}else{
//...
alert('更新完成!')
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  chrome extension