首页 文章

是否有可能在桌面通知正文javascript中显示图标

提问于
浏览
4

目前我要求在桌面通知机构内显示图像,但我不确定是否可能 -

notification = new Notification("title", "user1"), {
  icon: baseUrl + '/image/icon.png',
  body: "message"   // here i want add my custom image
});

如果可能的话,我需要实现它的方式 .

3 回答

  • 2

    您无法在Notification.body中添加图像,因为 body 属性仅接受根据MDN的字符串类型

  • 1

    你可以在icon属性中使用base64

    new Notification('name',{icon:/*base64 url*/})
    

    here是将图像转换为base64的网站

  • 2

    你有一个语法错误,如果你这样写,你可以在通知中放置几乎每个图片/图标 .

    var notification = new Notification("Hi there!", {
            icon: 'http://placekitten.com.s3.amazonaws.com/homepage-samples/96/139.jpg',
            body: 'Picture from https://placekitten.com/'
            })
    

    this fiddle - 代码取自mdn

相关问题