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
- (images) When the user aborts the loading of an image.
onblur
- (windows, form elements) When a form element loses focus or when a window or frame loses focus.
onchange
- (text fields, textareas, select lists) When a Select, Text, or Textarea field loses focus and its value has been modified
oncontextmenu
- When the user right-clicks on an element
onclick
- (buttons, radio buttons, checkboxes, submit buttons, reset buttons, links) When an object on a form is clicked.
ondblclick
- When the user double-clicks a form element or a link.
ondragdrop
- (windows) When the user drops an object onto the browser window, such as dropping a file.
onerror
- (images, windows) When the loading of a document or image causes an error.
onfocus
- (windows, form elements) When a window, frame, or frameset receives focus or when a form element receives input focus.
onkeydown
- (documents, images, links, text areas) When the user depresses a key.
onkeypress
- (documents, images, links, text areas) When the user presses or holds down a key.
onkeyup
- (documents, images, links, text areas) When the user releases a key.
onload
- (document body, images) When the browser finishes loading a window, image, or all frames within a FRAMESET tag.
onmousedown
- (documents, buttons, links) When the user depresses a mouse button.
onmousemove
- When the user moves the cursor.
onmouseout
- (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
- (links) Executes JavaScript code once each time the mouse pointer moves over an object or area from outside that object or area.
onmouseup
- (documents, buttons, links) When the user releases a mouse button.
onmove
- (windows) When the user or script moves a window or frame.
onreset
- (forms) When a user resets a form (clicks a Reset button).
onresize
- (windows) When a user or script resizes a window or frame.
onselect
- (text fields, textareas) When a user selects some of the text within a text or textarea field.
onsubmit
- (forms) When a user submits a form.
onunload
- (document body) When the user exits a document.
Resources URL:
notes/javascript/resources
Sources URL:
notes/javascript/sources