onvolumechangeEvent

事件对象参考手册Event Object

Example

Execute JavaScript when the volume of a video changes:

<video onvolumechange="myFunction()">

Try it yourself »

More examples are included at the bottom of this article.


Definition and Usage

The onvolumechange event is triggered when the volume of a video/audio (audio/video) changes.

This event can be invoked by:

  • Increasing or decreasing the volume
  • Muting or unmuting the media player

Tip:Use the Audio or Video object'svolumeproperty to set or return the volume of the video/audio (audio/video).


Browser Support

The numbers in the table indicate the first browser version that supports this event.

Event
onvolumechange Yes 9.0 Yes Yes Yes


Syntax

In HTML:

<element onvolumechange="myScript">Try it yourself

In JavaScript:

object.onvolumechange=function(){myScript};Try it yourself

In JavaScript, using the addEventListener() method:

object.addEventListener("volumechange", myScript);Try it yourself

Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()method.


Technical Details
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio>, <video>


Examples

More Examples

Example

Execute JavaScript when the volume of an audio changes:

<audio onvolumechange="myFunction()">

Try it yourself »

Example

Set the volume using the volume property:

document.getElementById("myVideo").volume = 0.2;

Try it yourself »


事件对象参考手册Event Object Other Extensions