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

{{APIRef("Web Notifications")}}

Note: 这个属性并没有完全被一些浏览器支持.

 sound 是 {{domxref("Notification")}}的只读属性,interface specifies the URL of an audio file to be played when the notification fires. This is specified in the sound option of the {{domxref("Notification.Notification","Notification()")}} constructor.

Syntax

var sound = Notification.sound;

Value

A {{domxref("USVString")}}.

Examples

The following snippet is intended to fire a sound along with the notification; a simple options object is created, then the notification is fired using the Notification() constructor.

var options = {
  body: 'Do you like my body?',
  sound: 'audio/alert.mp3'
}

var n = new Notification('Test notification',options);

n.sound // should return 'audio/alert.mp3'

Specifications

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

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{ CompatNo() }}

{{ CompatNo() }}

{{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

{{ CompatNo() }}

Firefox OS notes

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

Chrome notes

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

Safari notes

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

See also