--- title: Notification.body slug: Web/API/notification/body translation_of: Web/API/Notification/body ---

{{APIRef("Web Notifications")}}

 {{domxref("Notification")}} 的只读属性body返回了构造函数{{domxref("Notification")}}实例化时,options所使用的body值。

{{AvailableInWorkers}}

语法

var body = Notification.body;

{{domxref("DOMString")}}.

示例

在 Emogotchi demo (see source code)中, 我们在激活一个桌面通知时,调用了spawnNotification()函数—函数被传入了指定的参数 body、icon、title , 创建了一个必选对象传入{{domxref("Notification.Notification","Notification()")}} 构造函数创建了一个实例.

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

规范

Specification Status Comment
{{SpecName('Web Notifications','#dom-notification-body','body')}} {{Spec2('Web Notifications')}} Living standard

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 {{ property_prefix("webkit") }} (see notes)
22
{{CompatVersionUnknown}} 4.0 {{ property_prefix("moz") }} (see notes)
22
{{ CompatNo() }} 25 6 (see notes)
Available in workers {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoDesktop("41.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{ CompatUnknown() }}

{{CompatVersionUnknown}}

{{CompatVersionUnknown}} 4.0 {{ property_prefix("moz") }} (see notes)
22
1.0.1 {{ property_prefix("moz") }} (see notes)
1.2
{{ CompatNo() }} {{ CompatUnknown() }} {{ CompatNo() }}

{{CompatVersionUnknown}}

Available in workers {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile(41.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

Firefox OS 备忘

{{Page("/en-US/docs/Web/API/Notifications_API", "Firefox OS notes")}}

Chrome 备忘

{{Page("/en-US/docs/Web/API/Notifications_API", "Chrome notes")}}

Safari 备忘

{{Page("/en-US/docs/Web/API/Notifications_API", "Safari notes")}}

相关链接