Events
body onload vs window.onload
<body onload="...">...</body>
window.onload = myFunc;
- They refer to the same event instance
- window.onload is more flexible and doesn't require touching the
HTML code
- If window.onload is set in the header, it will be overridden by
body onload
- If window.onload is set in the body, it will override body onload
onunload
window.onunload = function(){};
- Ensures that the onload function runs in Firefox when the users
returns to the page via the browser's back button
- The function doesn't have to do anything, it just has to exist
Event handlers
onabort
- (1.1) (images) When the user aborts the
loading of an
image.
onblur
- (1.1) (windows, form elements) When a
form element
loses focus or when a window or frame loses focus.
onchange
- (1.1) (text fields, textareas, select
lists) When a
Select, Text, or Textarea field loses focus and its value has been
modified
onclick
- (1.1) (buttons, radio buttons,
checkboxes, submit
buttons, reset buttons, links) When an object on a form is clicked.
ondblclick
- (1.2) When the user double-clicks a form
element or
a link.
ondragdrop
- (1.2) (windows) When the user drops an
object onto
the browser window, such as dropping a file.
onerror
- (1.1) (images, windows) When the loading
of a document
or image causes an error.
onfocus
- (1.2) (windows, form elements) When a
window, frame,
or frameset receives focus or when a form element receives input focus.
onkeydown
- (1.2) (documents, images, links, text
areas) When
the user depresses a key.
onkeypress
- (1.2) (documents, images, links, text
areas) When
the user presses or holds down a key.
onkeyup
- (1.2) (documents, images, links, text
areas) When the
user releases a key.
onload
- (1.1) (document body, images) When the browser
finishes loading
a window, image, or all frames within a FRAMESET tag.
onmousedown
- (1.2) (documents, buttons, links) When
the user
depresses a mouse button.
onmousemove
- (1.2) When the user moves the cursor.
onmouseout
- (1.1) (areas, links) Executes JavaScript
code each
time the mouse pointer leaves an area (client-side image map) or link
from inside that area or link.
onmouseover
- (1.1) (links) Executes JavaScript code
once each
time the mouse pointer moves over an object or area from outside that
object or area.
onmouseup
- (1.2) (documents, buttons, links) When
the user
releases a mouse button.
onmove
- (1.2) (windows) When the user or script
moves a window
or frame.
onreset
- (1.1) (forms) When a user resets a form
(clicks a
Reset button).
onresize
- (1.2) (windows) When a user or script
resizes a
window or frame.
onselect
- (1.0) (text fields, textareas) When a
user selects
some of the text within a text or textarea field.
onsubmit
- (1.0) (forms) When a user submits a form.
onunload
- (1.0) (document body) When the user exits
a document.