Chrome扩展通知中的Json文件内容

时间:2018-06-06 02:30:39

标签: json google-chrome-extension push-notification

我可以在我的Chrome通知创建方法中插入json文件中的值吗?我想从json文件中获取图标和内容

1 个答案:

答案 0 :(得分:0)

首先,您需要在manifest.json中添加权限:

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

我假设你有这样的json:

var noti = {
            "iconUrl":"logo.png", 
            "title":"Frst Notification", 
            "message":"This is a chrome extension notification"
          };

使用此简单代码创建通知。

 chrome.notifications.create('Notifiy-1', {
        type: 'basic',
        iconUrl: noti.iconUrl,
        title: noti.title,
        message: noti.message
    }, function(notificationId) {});