HTML 4 adds the ability to trigger actions in the browser through events, such as launching a piece of JavaScript when the user clicks on an element.
event
(HTML attribute)
HTML 4 adds pass events
A large number of event handlers are built into modern browsers. These processors monitor specific conditions or user behavior, such as a mouse click or the completion of loading an image in a browser window. By using client-side JavaScript, you can add certain specific event handlers as attributes to specific tags, and you can execute one or more JavaScript commands or functions when an event occurs.
The value of the event handler is one or a series of Javascript expressions, methods, and function calls separated by semicolons and enclosed in quotes. When an event occurs, the browser executes this code.
The event triggered by the window object.
Applies to the <body> tag:
Attributes
value
description
onafterprint
script
Run the script after printing the document
onbeforeprint
script
Run the script before the document is printed
onbeforeonload
script
Run the script before the document loads
onblur
script
Run script when window loses focus
onerror
script
Run script when error occurs
onfocus
script
Run script when window gets focus
onhaschange
script
Run script when document changes
onload
script
Run the script when the document loads
onmessage
script
Run script when message is triggered
onoffline
script
Run script when document is offline
ononline
script
Run script when document is online
onpagehide
script
Run script when window is hidden
onpageshow
script
Run script when window is visible
onpopstate
script
Run script when window history changes
onredo
script
Run the script when the document performs redo
onresize
script
Run script when resizing window
onstorage
script
Run the script when the Web Storage area is updated (when the data in the storage space changes)
onundo
script
Run script when document performs undo
onunload
script
Run the script when the user leaves the document
Events triggered by actions inside HTML forms.
Works on all HTML 5 elements, but most commonly used in form elements: [1]
Events triggered by the keyboard.
Applicable to all
Events triggered by a mouse or similar user action.
Applies to all HTML 5 elements:
Attributes
value
description
Events triggered by media such as video, images, and audio.
Applies to all HTML 5 elements, but is most commonly used in media elements such as audio, embed, img, object, and video:
Attributes
value
description
onabort
script
Run script when abort event occurs
oncanplay
script
Run the script when the media is able to start playing but may need to stop due to buffering
oncanplaythrough
script
Run script when media can play to the end without stopping due to buffering
ondurationchange
script
Run script when media length changes
onemptied
script
Run a script when a media resource element is suddenly empty (network error, loading error, etc.)
onended
script
Run the script when the medium has reached the end
onerror
script
Run script when an error occurs during element loading
onloadeddata
script
Run script when media data is loaded
onloadedmetadata
script
Run the script when the duration of the media element and other media data are loaded
onloadstart
script
Run script when browser starts to load media data
onpause
script
Run script when media data is paused
onplay
script
Run script when media data is about to start playing
onplaying
script
Run script when media data has started playing
onprogress
script
Run the script when the browser is fetching the media data
onratechange
script
Run script when media data playback rate changes
onreadystatechange
script
Run the script when the ready-state changes
onseeked
script
Run the script when the positioning property [1] of the media element is no longer true and the positioning has ended
onseeking
script
Run script when media element's positioning property is true and positioning has started
onstalled
script
Run the script when there is an error (delay) during the retrieval of media data
onsuspend
script
Run the script when the browser is already fetching media data but stopped before retrieving the entire media file
ontimeupdate
script
Run script when media changes its playback position
onvolumechange
script
Run script when media changes volume or when volume is muted
onwaiting
script
Run the script when the media has stopped playing but intends to continue playing [2]