Notification的只读属性icon使得包含icon的 URL 被显示成通知的一部分,如同指定Notification()构造函数中icon的属性。

Note: 此特性在 Web Worker 中可用。

语法

var icon = Notification.icon;

一个 USVString

示例

在此示例中,当我们想要发出一个通知时,我们运行一个简单的 spawnNotification() 函数——这是传递参数来指定我们想要的主体、图标和标题,然后它创建必要的options对象,并使用Notification()构造函数来触发通知。

function spawnNotification(theBody,theIcon,theTitle) {
  var options = {
      body: theBody,
      icon: theIcon
  }
  var n = new Notification(theTitle,options);
}

Specifications

Specification Status Comment
Notifications API
icon
Living Standard Living standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
iconChrome Full support 22
Full support 22
Full support 5
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge Full support 14Firefox Full support 22
Full support 22
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
IE No support NoOpera Full support 25Safari No support NoWebView Android No support NoChrome Android Full support YesEdge Mobile ? Firefox Android Full support 22
Full support 22
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
Opera Android Full support YesSafari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

参见

文档标签和贡献者

标签: 
此页面的贡献者: mdnwebdocs-bot, zhangchen, alery123456
最后编辑者: mdnwebdocs-bot,