【问题标题】:Json file content in chrome extension notifications [closed]chrome扩展通知中的Json文件内容[关闭]
【发布时间】:2018-06-06 02:30:39
【问题描述】:

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

【问题讨论】:

  • 为什么不呢?如果它在可访问的位置,那么只需使用 XMLHttpRequest 读取它并解析。
  • 请分享一些样本。

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


【解决方案1】:

首先你需要在 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) {});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多