HTML onplay Attribute
The HTML onplay Attribute is a event attribute which occurs when the audio/video is played. The audio/video can be played either by the user or programmatically.
Supported Tags:
Syntax:
<element onplay="myScript">
Attribute Value: This attribute contains single value script which works when onplay event attribute call. This attribute is supported by <audio> and <video> tags.
Example 1:
html
<!DOCTYPE html> < html > < head > < title > HTML onplay Attribute </ title > </ head > < body > < center > < h1 style = "color: green;" > BeginnerforGeks </ h1 > < h2 >HTML onplay Attribute</ h2 > < audio controls id = "audID" onplay = "GFGfun()" > < source src = "https://media.w3wiki.net/wp-content/uploads/20190625153922/frog.mp3" type = "audio/mpeg" /> </ audio > < script > function GFGfun() { alert("audio play"); } </ script > </ center > </ body > </ html > |
Output:
After clicking on play Button:
Example 2:
html
<!DOCTYPE html> < html > < head > < title > HTML onplay Attribute </ title > </ head > < body > < center > < h1 style = "color: green;" > BeginnerforGeks </ h1 > < h2 >HTML onplay Attribute</ h2 > < video controls id = "vidID" onplay = "GFGfun()" width = "320" height = "240" > < source src = "https://media.w3wiki.net/wp-content/uploads/20190401140735/g4g2.mp4" type = "video/mp4" /> </ video > < script > function GFGfun() { alert("Video play"); } </ script > </ center > </ body > </ html > |
Output:
After:
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Apple Safari
- Opera