The JavaScript object
This page gives a list of objects, properties, collections and methods for documents and JavaScript components. This view of all properties available from the respective element types is referred to as the JavaScript object.
Some browsers may provide aditional properties or methods but as this stage of the tutorial is intended to teach you how to program so that your scripts work in all the possible (so called 4th generation) browsers, I have given those that are available in all possible browsers or those which have an alternative, which I will also have given. This is the last chapter of this tutorial where I will deal with such a wide range of browsers. In the next few chapters, I will abandon 4th generation browsers, and move on to the much more advanced DOM browsers (also known as 5th generation browsers).
Contents
- Standard document components - all addressable components of a web page.
- Positioned elements - all addressable components of an absolutely positioned div.
- Event objects - all accessible information about an event.
- Intrinsic objects - variable types with constructors.
Key
- Parent object
- Child object
- Child property
- Child object being accessed through a collection[]
- Event
- Method()
For items written in the format: 'methodName([someOtherStuff])
', someOtherStuff is optional and does not need
to be written. The [] brackets must be removed. For items written in the format
'methodName(type varName)'
, 'type' gives the type of variable expected by the method or collection,
called varName in this case.
To use this structure to refer to any object, property, collection or method, treat each new branch level as a new child level. For example:
window.document.nameOfForm.nameOfInput.defaultValue = 'I love it';
Note, all collections also have the length attribute. Also note, window is often omitted when referring to child objects.
Standard document components
- window or self Refers to the global object of the current Web page - - read-only
- Array Only useful as a constructor - - read-only
- Boolean Only useful as a constructor - - read-only
- closed This will be true if the window is closed - (used with window.open()) - - read-only
- Date Mostly useful as a constructor - - read-only
- parse(string dateAsAString) Date.parse(string dateAsAString) converts a string into a UNIX timestamp (milli) - Accepts almost any valid date and/or time string format
- defaultStatus Refers to the default message displayed in the status bar - Some browsers allow users to disable the ability to write to this toolbar - - read-write
- document windowObject.document refers to the current document - In a positioned element using layers syntax, - positionedElementObject.document refers to the body of the positioned element - - read-only
- bgColor Refers to the default background colour of the document - - read-write - - Layers browsers only - For cross-browser scripting, see also - document.body.style.backgroundColor - document.documentElement.style.backgroundColor
- body Holds information about the BODY element of the current Page - This object may exist without any of its properties existing - - read-only - - Non-layers browsers only
- clientHeight Represents the height of the inside of the browser window in pixels - In most browsers in strict mode, it represents the height of the document area - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.innerHeight - document.documentElement.clientHeight
- clientWidth Represents the width of the inside of the browser window in pixels - In most browsers in strict mode, it represents the width of the document area - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.innerWidth - document.documentElement.clientWdth
- scrollLeft Represents the horizontal scrolling of the document in pixels - Some browsers will give 0 if they are currently providing the scrolling offset via - document.documentElement.scrollLeft - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.pageXOffset - document.documentElement.scrollLeft
- scrollTop Represents the vertical scrolling of the document in pixels - Some browsers will give 0 if they are currently providing the scrolling offset via - document.documentElement.scrollTop - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.pageYOffset - document.documentElement.scrollTop
- style If available, this refers to the style of the BODY element - - read-only
- background Refers to the default background style of the BODY - equivalent to backgroundColor in Opera 6- - Not available in Opera 5 - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - document.bgColor - document.documentElement.style.background
- backgroundColor Refers to the default background colour of the BODY - Not available in Opera 5 - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - document.bgColor - document.documentElement.style.backgroundColor
- color Refers to the default colour of the text in the BODY - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - document.fgColor - document.documentElement.style.color
- cookie String representation of all cookies available to the current web page - This can be used to create and read cookies - - read-write
- documentElement Holds information about the HTML element of the current page - this object may exist without any of its properties existing - - read-only - - Non-layers browsers only
- clientHeight Represents the height of the document area in pixels - In most browsers in strict mode, it represents the height of the inside of the browser window - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.innerHeight - document.body.clientHeight
- clientWidth Represents the width of the document area in pixels - I most browsers in strict mode, it represents the width of the inside of the browser window - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.innerWidth - document.body.clientwidth
- scrollLeft Represents the horizontal scrolling of the document in pixels - Some browsers will give 0 if they are currently providing the scrolling offset via - document.body.scrollLeft - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.pageXOffset - document.body.scrollLeft
- scrollTop Represents the vertical scrolling of the document in pixels - Some browsers will give 0 if they are currently providing the scrolling offset via - document.body.scrollTop - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - window.pageYOffset - document.body.scrollTop
- style If available, this refers to the style of the HTML element - - read-only
- background Refers to the default background style of the HTML element - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - document.bgColor - document.body.style.background
- backgroundColor Refers to the default background colour of the HTML element - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - document.bgColor - document.body.style.backgroundColor
- color Refers to the default colour of the text in the HTML element - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - document.fgColor - document.body.style.color
- domain String representation of the domain name holding the document - representations may vary - - read-write in some browsers (allows related subdomains to communicate)
- fgColor Refers to the default colour of the text in the document - - read-write but becomes read-only after the document has loaded - - Layers browsers only - For cross-browser scripting, see also - document.body.style.color - document.documentElement.style.color
- IdOfPositionedElement Refers to a positioned element in a - layers alternative compatible browser - - read-only - - Layers browsers only - For cross-browser scripting, see also - document.layers - document.all - document.getElementById
- lastModified String representation of the last modified date of the document - Representations may vary - May be the current date or the UNIX epoch if not provided - - read-only
- location A reference to window.location
- nameOfForm Refers to a form in the document - - read-only
- action Refers to the action attribute of a form - - read-write
- encoding Refers to the enctype attribute of a form - - read-write
- length The number of inputs - - read-only
- method Refers to the method attribute of a form - - read-write
- name Refers to the name attribute of a form - - read-write
- nameOfInput/textarea/select or nameOfInputsSharingName[int index] Refers to an input, textarea or select - nameOfInput will not work if inputs share a common name, but this - branch does give the children of these inputs referred to using the - nameOfInputsSharingName collection - nameOfInputsSharingName.length gives number of inputs sharing - that name, eg. the number of radio input options - - read-only
- checked Boolean: says if a checkbox or radio button is checked - - read-write
- defaultChecked Boolean: says if a checkbox or radio button will be checked if the form is reset - - read-write
- defaultValue Refers to the default value of the input - This will be used if the form is reset - Some browsers do not give this attribute for buttons of any kind - Different browsers give different responses for select inputs; do not rely on it - - read-write
- disabled Boolean: says if the input is disabled, if the browser supports it - Netscape 4 does not support it and Opera 5 will not change the value - of the attribute unless the page is refreshed in between (this bug can - cause problems) - - read-write
- form Refers back to the form containing the input - - read-only
- length Refers to the number of options in a select input - or the number of inputs sharing that name - - read-only
- name Refers to the name attribute of an input - - read-write
- selectedIndex The option number currently selected in a select input - -1 if none - - read-write in all except Internet Explorer 4
- type Refers to the type attribute of an input - May be in upper or lower case - - read-only except for select where type can specify - if single ('select-one') or multiple ('select-multiple') - options can be selected
- value The current value of an input - Different browsers give different responses for select inputs; do not rely on it - - read-write
- options[int numberOfOptionWithSelectInput] Refers to an option in a select input - - read-write - - selectObject.options.length gives the current number of options - - read-write - - Create a new option using - optionObject = new Option(string text,string value) - Delete an option by setting it to null
- defaultSelected Boolean: says if the input is the one that is selected when the form is reset - - read-write
- index Refers to the number of the option - - read-only
- selected Boolean: says if the option is selected - - read-write
- text Refers to the visible text of an option - - read-write
- value Refers to the value of an option - - read-write
- onblur Fires when the input looses focus - inputObject.onblur = functionName; - - read-write
- onchange Fires when the value of the input changes or a different option is selected - inputObject.onchange = functionName; - - read-write
- onclick Fires when the user depresses then releases a mouse button over the input - or if the input is activated using the keyboard (whereas mouse event - properties are not provided) - inputObject.onclick = functionName; - - read-write
- ondblclick Fires when the user depresses then releases a mouse button twice - in quick succession over the input - inputObject.ondblclick = functionName; - Old Mac browsers (as well as a few others) generally do not detect this event - It is possible to emulate this event's response using a combination - of onclick and window.setTimeout - - read-write
- onfocus Fires when the input receives focus - inputObject.onfocus = functionName; - - read-write
- onkeydown Fires when the user presses a key down while the input has the focus - inputObject.onkeydown = functionName; - Some versions of Netscape 4 do not react but they will react to - document.onkeydown while the input has the focus - - read-write - Returning false will prevent the default keydown/press action in most browsers
- onkeypress Fires when the user presses and releases a key while the input has the focus - inputObject.onkeypress = functionName; - Some versions of Netscape 4 do not react but they will react to - document.onkeypress while the input has the focus - - read-write - Returning false will prevent the default keypress action in most browsers
- onkeyup Fires when the user releases a key while the input has the focus - inputObject.onkeyup = functionName; - Some versions of Netscape 4 do not react but they will react to - document.onkeyup while the input has the focus - - read-write
- onmousedown Fires when the user depresses a mouse button over the input - inputObject.onmousedown = functionName; - - read-write - Returning false from a right button mousedown will prevent the right click - menu from appearing in some browsers - Some may need you to return false from an oncontextmenu event and some - do not detect right clicks
- onmouseup Fires when the user releases a mouse button over the input - inputObject.onmouseup = functionName; - - read-write
- blur() Causes the input to loose focus
- focus() Causes the input to receive focus
- select() Causes the text in a text-based input to be selected
- target Refers to the target attribute of a form - - read-write
- elements[int numberOfInput] Refers to a non-image input - - read-only - - formObject.elements.length gives the number of inputs - - read-only
- onreset Fires when the form is reset - If you return false, the reset will be cancelled and the form will not be reset - inputObject.onreset = functionName; - - read-write
- onsubmit Fires when the form is submitted - If you return false, the submit will be cancelled and the form will not be submitted - inputObject.onreset = functionName; - - read-write
- reset() Causes the form to reset
- submit() Causes the form to be submitted
- nameOfImage Refers to an image - - read-only - - create a new image (stored in cache) using - imageObject = new Image(); imageObject.src = string src;
- border Refers to the border of an image - - read-write
- complete Boolean: says if an image has completed loading - - read-only
- height Refers to the height of an image - - read-write
- lowsrc Refers to the lowsrc of an image - - read-write
- name Refers to the name of an image - - read-write (read-only in some old browsers)
- src Refers to the src of an image - - read-write
- width Refers to the width of an image - - read-write
- onabort Fires if the user aborts the loading of that image - imageObject.onabort = functionName; - - read-write
- onerror Fires if the image fails to load due to errors in the image source or - if the image cannot be located - imageObject.onerror = functionName; - - read-write
- onload Fires as soon as the image loads - imageObject.onload = functionName; - Some browsers do not fire this event for cached images - - read-write
- onmousedown Fires when the user depresses a mouse button over the image - imageObject.onmousedown = functionName; - - read-write - - Returning false from a right button mousedown will prevent the right click - menu from appearing in some browsers - Some may need you to return false from an oncontextmenu event and some - do not detect right clicks
- onmouseup Fires when the user releases a mouse button over the image - imageObject.onmouseup = functionName; - - read-write
- referrer The URL of the page that contained a link that the user - clicked on to get to this page - representations may vary - Some browser allow users to disable this property - - read-only
- title Refers to the document title - - read-only in old browsers - - read-write in new browsers
- URL The full text of the location - as window.location.href except read-only - - read-only
- all[string IdOfElement] Refers to an element in a - proprietary DOM compatible browser - See Positioned Element - - read-only - - Proprietary DOM browsers only - For cross-browser scripting, see also - document.IdOfPositionedElement - document.layers - document.getElementById
- anchors[int numberOfATagWithNameDefined] Refers to an <a ...> tag where the name attribute has been set - - read-only - - documentObject.anchors.length gives the current number of anchor - elements whose name attribute has been set - - read-only
- name Refers to the name attribute of an anchor - - read-write
- offsetLeft The distance between the left edge of the anchor and the left edge of - the offsetParent node - See the section on browser specific referencing for how to use this - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - anchorObject.x
- offsetParent The offsetParent node - this may be different in different browsers - See the section on browser specific referencing for how to use this - - read-only - - Non-layers browsers only
- offsetTop The distance between the top edge of the anchor and the top edge of - the offsetParent node - See the section on browser specific referencing for how to use this - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - anchorObject.y
- x The distance between the left edge of the anchor and the left edge of the page - - read-only - - Layers browsers only - For cross-browser scripting, see also - linkObject.offsetLeft recursively with anchorObject.offsetParent
- y The distance between the top edge of the anchor and the top edge of the page - - read-only - - Layers browsers only - For cross-browser scripting, see also - linkObject.offsetTop recursively with anchorObject.offsetParent
- applets[int numberOfAppletTag] Refers to an applet in the document - - read-only
- nameOfPublicProperty All public properties of the applet are available - - read-only/read-write
- nameOfPublicMethod() All public methods of the applet are available - - read-only/read-write
- embeds[nameOrNumberOfEmbeddedObject] Refers to an embed element in the document - In many browsers, this array requires Java to be enabled - If the browser does not have Java enabled, the script - will produce an error and will abort if you attempt to - reference this array - If the plugin or the embedded object fails to load, Netscape 4 - will produce an error if you attempt to reference the - corresponding cell of the embeds array - - This array is empty in IE/Win and iCab 3- - - See also document.plugins - - read-only
- height Refers to the height of the embedded object - - read-only
- hidden Refers to the hidden attribute of the embedded object - - read-only
- name Refers to the name of the embedded object - - read-only
- pluginspage Refers to the pluginspage attribute of the embedded object - - read-write
- src Refers to the src of the embedded object - - read-write
- type Refers to the data type of the embedded object - - read-only
- units Refers to the units of the embedded object - (usu. 'pixels' in Netscape compatible or 'px' in - Internet Explorer compatible) - - read-only
- width Refers to the width of an the embedded object - - read-only
- onload Fires as soon as the embedded object loads - embeddedObject.onload = functionName; - - read-write
- nameOfPublicMethod() All public methods of the embedded object are available - These will vary with the plugin type - See the plugin provider's page - - read-only/read-write
- forms[int numberOfForm] Refers to a form in the document - Children as window.document.nameOfForm - - read-only
- images[nameOrNumberOfImage] Refers to an image in the document - Children as window.document.nameOfImage - - read-only
- layers[string IdOfPositionedElement] Refers to a positioned element in a - layers compatible browser - See Positioned Element - - read-only - - Layers browsers only - For cross-browser scripting, see also - document.IdOfPositionedElement - document.all - document.getElementById
- links[int numberOfATagWithHrefDefined] Refers to an <a ...> or <area ...> tag where the HREF attribute has been set - - read-only - - documentObject.links.length gives the current number of anchor or area - elements whose href attribute has been set - - read-only
- hash The part of the href after the # symbol (if there is one) - The hash symbol is also returned when reading this - The hash symbol should not be included when setting this - Internet Explorer (Win/Mac), Gecko and iCab 3- return a blank string if hash is just '#' - ICEbrowser returns the entire href without the hash - - read-write
- host The host name and port number (if there is one) of the href - - read-write
- hostname The host name of the href - - read-write
- href The full text of the href - - read-write
- innerText The visible text of the link - - read-only - - Proprietary DOM browsers only - For cross-browser scripting, see also - linkObject.text
- offsetLeft The distance between the left edge of the link and the left edge of - the offsetParent node - See the section on browser specific referencing for how to use this - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - linkObject.x
- offsetParent The offsetParent node - This may be different in different browsers - See the section on browser specific referencing for how to use this - - read-only
- offsetTop The distance between the top edge of the link and the top edge of - the offsetParent node - See the section on browser specific referencing for how to use this - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - linkObject.y
- pathname The part of the href after the host name - eg. subdir1/subdir2/file.html - - read-write
- port The port number (if there is one) - - read-write
- protocol The protocol used - eg. http: - - read-write
- search The part of the href after (and containing) the ? symbol, if there is one - - read-write
- target The target of the link - - read-write
- text The visible text of the link - - read-only - - A bug in Netscape 4 makes this only available if - the name attribute is not set - - Layers browsers only - For cross-browser scripting, see also - linkObject.innerText
- x The distance between the left edge of the link and the left edge of the page - - read-only - - A bug in Netscape 4 makes this only available if the name attribute is not set - If it is, use the x property of the corresponding anchor object - - Layers browsers only - For cross-browser scripting, see also - linkObject.offsetLeft recursively with linkObject.offsetParent
- y The distance between the top edge of the link and the top edge of the page - - read-only - - A bug in Netscape 4 makes this only available if the name attribute is not set - If it is, use the y property of the corresponding anchor object - - Layers browsers only - For cross-browser scripting, see also - linkObject.offsetTop recursively with linkObject.offsetParent
- onblur Fires when the link looses focus - anchorObject.onblur = functionName; - - read-write
- onclick Fires when the user depresses then releases a mouse button over the link - or if the link is activated using the keyboard (whereas mouse event - properties are not provided) - linkObject.onclick = functionName; - - read-write - - Returning false from a click will prevent the link from being followed
- ondblclick Fires when the user depresses then releases a mouse button twice - in quick succession over the link - linkObject.ondblclick = functionName; - Old Mac browsers (as well as a few others) generally do not detect this event - It is possible to emulate this event's response using a combination - of onclick and window.setTimeout - - read-write
- onfocus Fires when the link receives focus - anchorObject.onfocus = functionName; - - read-write
- onmousedown Fires when the user depresses a mouse button over the link - linkObject.onmousedown = functionName; - - read-write - - Returning false from a right button mousedown will prevent the right click - menu from appearing in some browsers - Some may need you to return false from an oncontextmenu event and some - do not detect right clicks
- onmousemove Fires when the user moves the mouse while it is over the link - linkObject.onmousemove = functionName; - Not available in Netscape 4 - - read-write
- onmouseout Fires when the user moves the mouse from over the link to off the link - linkObject.onmouseout = functionName; - - read-write
- onmouseover Fires when the user moves the mouse from off the link to over the link - linkObject.onmouseover = functionName; - - read-write - - If you set the status using this event, you will need to return true
- onmouseup Fires when the user releases a mouse button over the link - linkObject.onmouseup = functionName; - - read-write
- blur() Causes the link to loose focus - Not available in Netscape 4 - Check if the method exists before you try to use it - if( linkObject.blur ) { linkObject.blur(); }
- focus() Causes the link to receive focus - Not available in Netscape 4 - Check if the method exists before you try to use it - if( linkObject.focus ) { linkObject.focus(); }
- plugins[numberOfObject] Refers to an embed or object element in the document - (depending on what is supported by the browser) - In many browsers, this array requires Java to be enabled - If the browser does not have Java enabled, the script - will produce an error and will abort if you attempt to - reference this array - If the plugin or the embedded object fails to load, Netscape 4 - will produce an error if you attempt to reference the - corresponding cell of the embeds array - - This array is empty in IE/Win and iCab 3-, and does not - exist in older Konqueror/Safari/OmniWeb - In Opera it will reference all object and embed tags even if - they are not being used - In Mozilla/Firefox it will only contain objects or embeds - that have actually loaded plugins - - Children as for document.embeds - - read-only
- onclick Fires when the user depresses then releases a mouse button over the document - documentObject.onclick = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- ondblclick Fires when the user depresses then releases a mouse button twice - in quick succession over the document - documentObject.ondblclick = functionName; - Old Mac browsers (as well as a few others) generally do not detect this event - It is possible to emulate this event's response using a combination - of onclick and window.setTimeout - - Layers browsers will require you to use captureEvents first - - read-write
- onkeydown Fires when the user presses a key down while the document - (but not an input) has the focus - documentObject.onkeydown = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onkeypress Fires when the user presses and releases a key down while - the document (but not an input) has the focus - documentObject.onkeypress = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onkeyup Fires when the user releases a key while the document - (but not an input) has the focus - documentObject.onkeyup = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmousedown Fires when the user depresses a mouse button over the document - documentObject.onmousedown = functionName; - - Layers browsers will require you to use captureEvents first - - read-write - - Returning false from a right button mousedown will prevent the right click - menu from appearing in some browsers - Some may need you to return false from an oncontextmenu event and some - do not detect right clicks
- onmousemove Fires when the user moves the mouse while it is over the document - documentObject.onmousemove = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmouseout Fires when the user moves the mouse from over the document to off the document - documentObject.onmouseout = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmouseover Fires when the user moves the mouse from off the document to over the document - documentObject.onmouseover = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmouseup Fires when the user releases a mouse button over the document - documentObject.onmouseup = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- captureEvents(Event.EventType) Causes layers browsers to react to events - see window.Event for what events can be captured
- close() Says that you have stopped rewriting the document contents - and they should now be displayed
- getElementById(string IdOfElement) Returns a reference to an element in a - DOM compatible browser - See Positioned Element - - read-only - - DOM browsers only - For cross-browser scripting, see also - document.IdOfPositionedElement - document.layers - document.all
- open() Says that you are about to start rewriting the document contents
- write(string content) Writes document content
- writeln(string content) Writes a line of document content
- event If the browser supports it, this holds the instantaneous details of an event - See the section on event objects below - - read-only - - Proprietary DOM browsers only - For cross-browser scripting, see also - event objects using first argument
- Event The event capture object provided by layers browsers - For use with capturing events - Some browsers that support DOM events will provide this, - but it serves no useful purpose
- CLICK Fires when the user depresses then releases a mouse button over the element - - read-only
- DBLCLICK Fires when the user depresses then releases a mouse button twice - in quick succession over the element - Old Mac browsers (as well as a few others) generally do not detect this event - It is possible to emulate this event's response using a combination - of onclick and window.setTimeout - - read-write
- KEYDOWN Fires when the user presses a key down while the element has the focus - - read-only
- KEYPRESS Fires when the user presses then releases a key while the element has the focus - - read-only
- KEYUP Fires when the user releases a key while the element has the focus - - read-only
- MOUSEDOWN Fires when the user depresses a mouse button over the element - - read-only
- MOUSEMOVE Fires when the user moves the mouse while it is over the element - - read-only
- MOUSEOUT Fires when the user moves the mouse from over the element - to off the element - - read-only
- MOUSEOVER Fires when the user moves the mouse from off the element - to over the element - - read-only
- MOUSEUP Fires when the user releases a mouse button over the element - - read-only
- Function Only useful as a constructor - - read-only
- history Refers to the document history of the browser - - read-only
- back() Loads the last document in the browser history - Equivalent to clicking the browser's back button
- forward() Loads the next document in the browser history - Equivalent to clicking the browser's forward button
- go(int numerToJump) Jumps forward through the browser history by the specified number of entries - Use -ve numbers for previous documents
- Image Only useful as a constructor - - read-only
- innerHeight Represents the height of the document area of the browser in pixels - in most browsers (not IE 8- or IE 9+ in quirks mode) - - read-only - - Netscape compatible browsers only - For cross-browser scripting, see also - document.body.clientHeight - document.documentElement.clientHeight
- innerWidth Represents the width of the document area of the browser in pixels - in most browsers (not IE 8- or IE 9+ in quirks mode) - - read-only - - Netscape compatible browsers only - For cross-browser scripting, see also - document.body.clientWidth - document.documentElement.clientWidth
- length Number of frames held by the current document - Equivalent to window.frames.length - - read-only
- location Holds information about the current location - - read-write - - Writing is equivalent to writing location.href
- hash The part of the location after the # symbol (if there is one) - The hash symbol is also returned when reading this - The hash symbol should not be included when setting this - Internet Explorer (Win/Mac), Gecko and iCab 3- return a blank string if hash is just '#' - ICEbrowser returns the entire href without the hash - - read-write
- host The host name and port number (if there is one) of the location - Internet Explorer 7- on windows always shows a port number, even if one is not specified in the href (it does not do this with links) - - read-write
- hostname The host name of the location - - read-write
- href The full text of the location - - read-write
- pathname The part of the location after the host name - eg. /subdir1/subdir2/file.html - - read-write
- port The port number (if there is one) - - read-write
- protocol The protocol used - eg. http: - - read-write
- search The part of the location after (and containing) the ? symbol, if there is one - - read-write
- reload([bool forceFullReload]) Reloads the current document - if forceFullReload is true, the document will be reloaded from the - server, not from cache
- replace(string location) Loads the specified URL replacing the current history entry - the URL can be relative or absolute
- Math An object containing mathematical constants and methods - - read-only
- E Constant - e - ~= - 2.718 - - read-only
- LN2 Constant - ln(2) - ~= - 0.693 - - read-only
- LN10 Constant - ln(10) - ~= - 2.303 - - read-only
- LOG2E Constant - log2(e) - ~= - 1.442 - - read-only
- LOG10E Constant - log10(e) - ~= - 0.434 - - read-only
- PI Constant - Pi - ~= - 3.142 - - read-only
- SQRT1_2 Constant - 1/sqrt(2) or sqrt(1/2) - ~= - 0.707 - - read-only
- SQRT2 Constant - sqrt(2) - ~= - 1.414 - - read-only
- abs(number n) Returns the absolute value of n
- acos(number n) Returns (rads) cos^-1 of n
- asin(number n) Returns (rads) sin^-1 of n
- atan(number n) Returns (rads) tan^-1 of n
- atan2(number n,number k) Returns the angle (rads) from cartesian coordinates 0,0 to n,k
- ceil(number n) Returns n rounded up to the nearest whole number
- cos(number n) Returns cos n (where n is in radians)
- exp(number n) Returns e to the power of n
- floor(number n) Returns n rounded down to the nearest whole number
- log(number n) Returns ln(n)
- max(number a,number b,number c,.....) Returns the largest number
- min(number a,number b,number c,.....) Rreturns the smallest number
- pow(number n,number k) Rturns n to the power of k
- random() Returns a random number between 0 and 1
- round(number n) Returns n rounded up or down to the nearest whole number
- sin(number n) Returns sin n (where n is in radians)
- sqrt(number n) Returns the square root of n
- tan(number n) Returns tan n (where n is in radians)
- name Refers to the name of the current window used by <a target= ...> - - read-write
- navigator Holds information about the user's browser - - read-only
- appCodeName The code name of the browser - Many browsers spoof this, never use it - - read-only
- appName The short name of the browser - Many browsers spoof this, never use it - - read-only
- appVersion The version number of the browser - Many browsers spoof this, never use it - - read-only
- language The user's choice of language for their browser - - read-only - - Netscape compatible browsers only
- platform The operating system the browser is running on - Many browsers spoof this, never use it - - read-only
- userAgent The full name of the browser - Many browsers spoof this, never use it - - read-only
- userLanguage The user's choice of language for their operating system - - read-only - - IE compatible browsers only
- mimeTypes[nameOrNumberOfMIMEType] Contains information about a MIME type supported by the browser - Internet Explorer on Windows just gives a 0 length array so - Just put the object on the page and the user will be prompted to - download the relevant plugin if they do not support it yet - - read-only
- description The full description of the MIME type - - read-only
- enabledPlugin Refers to the plugin that supports the MIME type - children as for window.navigator.plugins[nameOrNumberOfPlugin] - - read-only
- suffixes Gives a 'comma-space' separated list of the file extensions covered by the MIME type - - read-only
- type Gives the official type name of the MIME type - eg. image/gif - - read-only
- plugins[nameOrNumberOfPlugin] Contains information about a plugin - Internet Explorer on Windows just gives a 0 length array so - Just put the object on the page and the user will be prompted to - download the plugin if they do not support it yet - - read-only
- description The full name of the plugin - - read-only
- filename The full name of the plugin file - - read-only
- length The number of MIME types supported by the plugin - - read-only
- name The short name of the plugin - - read-only
- nameOrNumberOfMIMEType A reference to the associated entry in the navigator.mimeTypes collection - - read-only
- javaEnabled() Returns if the browser supports Java
- taintEnabled() Returns if the browser supports data tainting - Tainting is not supported by any '4th generation' - browsers so this method no longer serves any - purpose, although browsers still provide it
- Number Contains unusual constants and information about the browser's number handling - Can also be used as a constructor - - read-only
- MAX_VALUE Number.MAX_VALUE is the highest number that that browser on - that operating system can represent - - read-only
- MIN_VALUE Number.MIN_VALUE is the smallest positive number that that browser - on that operating system can represent - - read-only
- NaN Number.NaN is a non-number equivalent to eg. Math.sqrt(-1) - - read-only
- NEGATIVE_INFINITY Number.NEGATIVE_INFINITY is a special number representing negative infinity - - read-only
- POSITIVE_INFINITY Number.POSITIVE_INFINITY is a special number representing positive infinity - - read-only
- Object Only useful as a constructor - - read-only
- opener Refers to the window that used the window.open method to open this window - - read-write
- Option Only useful as a constructor - - read-only
- outerHeight Represents the height of the browser window in pixels - in most browsers (not IE 8- or IE 9+ in quirks mode) - - read-only - - There is no cross-browser equivalent - It is best to use this only to combat resizeTo inconsistencies
- outerWidth Represents the width of the browser window in pixels - in most browsers (not IE 8- or IE 9+ in quirks mode) - - read-only - - There is no cross-browser equivalent - It is best to use this only to combat resizeTo inconsistencies
- pageXOffset Represents the horizontal scrolling of the document in pixels - in most browsers (not IE 8- or IE 9+ in quirks mode) - - read-write - - Netscape compatible browsers only - For cross-browser scripting, see also - document.body.scrollLeft - document.documentElement.scrollLeft
- pageYOffset Represents the vertical scrolling of the document in pixels - in most browsers (not IE 8- or IE 9+ in quirks mode) - - read-write - - Netscape compatible browsers only - For cross-browser scripting, see also - document.body.scrollTop - document.documentElement.scrollTop
- parent Refers to the parent window in the frameset - - read-only
- RegExp Holds information about regular expression searches - Some browsers fail to implement this correctly (eg. Opera 6- and iCab 2-) - - read-only
- $1 ... $9 RegExp.$1 - RegExp.$9 store the last 9 capture matches found - during a regular expression search - - read-only
- input RegExp.input is the last string that a regular expression - search was performed against - - read-only
- lastMatch or $& RegExp.lastMatch is the last substring that fully matched a - regular expression during a match, exec or test - - read-only
- lastParen or $+ RegExp.lastParen is the last instance of any capture during - a match, exec or test - - read-only
- leftContext or $` RegExp.leftContext is the leading substring before the last - substring that fully matched a regular expression during a - match, exec or test - - read-only
- rightContext or $' RegExp.rightContext is the trailing substring after the last - substring that fully matched a regular expression during a - match, exec or test - - read-only
- screen Holds information about the user's monitor - - read-only
- availHeight The available height of the monitor in pixels when - The size of the taskbar is taken into account - - read-only
- availWidth The available width of the monitor in pixels when - The size of the taskbar is taken into account - - read-only
- colorDepth The number of bits per pixel if pixelDepth - is not provided - - read-only - - For cross-browser scripting, see also - pixelDepth
- height The height of the monitor in pixels - - read-only
- pixelDepth The number of bits per pixel, if provided - - read-only - - For cross-browser scripting, see also - colorDepth
- width The width of the monitor in pixels - - read-only
- status Refers to the text written in the status bar of the browser - Some browsers allow users to disable the ability to write to this toolbar - - read-write
- String Mostly useful as a constructor - Contains a useful character method - - read-only
- fromCharCode(number asciiCharacterValue) Returns the character represented by the numerical (ascii) value - - read-only
- frames[nameOrNumberOfFrame] Refers to an iframe element or the window object of a page held - in the frameset held by this page (you will need to use - window.frames[nameOrNumberOfFrame].window - to access the window object of the document held in an iframe) - - read-only - windowObject.frames.length gives the number of frames in the - frameset held by this page - NOTE: attempting to access a frame that does not contain an - HTML document or is from a different domain or an iframe - that has not loaded will cause errors in most browsers - - read-only
- name Refers to the name of a frame - - read-write
- onblur Fires when the window looses focus - windowObject.onblur = functionName; - - read-write
- onerror Fires when the script produces an error. - Setting this prevents the error dialog being displayed - windowObject.onerror = functionName; - or - windowObject.onerror = null; - Returning true will prevent the error being logged - - Not available in some browsers (like Opera), so use try{}catch(e){} instead - - read-write
- onfocus Fires when the window receives focus - windowObject.onfocus = functionName; - - read-write
- onload Fires as soon as the page loads - windowObject.onload = functionName; - IE 4 will get self.onload wrong (use window.onload) - - read-write
- onunload Fires just before the page unloads - windowObject.onunload = functionName; - - read-write
- alert(object) Displays a message box with a textual representation of the object. - If the object is a string, the string will be displayed
- blur() Causes the window to loose focus
- clearInterval(interval object) Stops the interval from firing again
- clearTimeout(timeout object) Stops the timeout from firing
- close() Causes the window to close - If the window was not opened by script, the user will - be asked if they want the window to close
- confirm(string message) Displays the message and offers 'OK' and 'Cancel' buttons - Returns true if the user chooses OK and false if the user chooses Cancel
- escape(string textToURLEncode) Returns the string URL encoded - Not unicode-safe
- eval(string scriptToEvaluate) Evaluates the text as a script
- focus() Causes the window to receive focus
- isFinite(number numberToCheck) Returns if the number is a proper number with a finite value - not NaN or Infinity or -Infinity
- isNaN(number numberToCheck) Returns if the number is NaN (eg. Math.sqrt(-1))
- moveBy(int xOffset,int yOffset) Moves the browser window by the specified amount
- moveTo(int xPos,int yPos) Moves the browser window to the specified coordinate
- open(string url[,string targetName[,string options[,bool replaceHistoryEntry]]]) Opens the URL specified with the settings provided - Returns a reference to the window - The targetName is used by <a target= ...> - Options is a string containing a comma separated list of - option=value where value is an integer giving a size or - yes or 1 to enable the option or no or 0 to disable it - available options are: - height=int height of window - left=int distance between left side of window and left side of screen - location=enable/disable - menubar=enable/disable - resizable=enable/disable - scrollbars=enable/disable - status=enable/disable - toolbar=enable/disable - top=int distance between top of window and top of screen - width=int width of window - Some browsers may offer more - Leave any out to resort to their defaults
- parseInt(string textContainingAnInteger[, int radix]) Returns the integer part of a string - If radix is provided, the number will be interpreted in the base - of that radix (typically 8, 10 or 16) - If radix is not provided, older browsers will auto-detect leading - '0x' as Hex, leading '0' as octal, and all others as decimal.
- parseFloat(string textContainingAFloat) Returns the float part of a string
- print() Displays the print dialog box allowing the user to print the current document - Not available in some older browsers
- prompt(string message,string defaultValue) Displays a prompt allowing the user to input a variable value - Returns the user-inputted value as a string - Returns null or undefined if the user chooses cancel
- resizeBy(int xOffset,int yOffset) Resizes the browser window by the specified amount
- resizeTo(int xWidth,int yWidth) Resizes the browser window to the specified amount
- scrollBy(int xOffset,int yOffset) Scrolls the document by the specified amount
- scroll or scrollTo(int xPos,int yPos) Scrolls the document to the specified coordinate
- setInterval(string or function scriptToEvaluate,int timeInMilliseconds) Repeatedly waits for the specified amount of time - before evaluating the code specified - Returns an integer reference to the interval object
- setTimeout(string or function scriptToEvaluate,int timeInMilliseconds) Waits for the specified amount of time - before evaluating the code specified - Returns an integer reference to the timeout object
- unescape(string textToURLUnEncode) Returns the string URL unencoded - Not unicode-safe
Positioned elements
In DOM and proprietary DOM browsers, this could actually be any element, not just one that is positioned. However, at this stage of the tutorial, only 4th generation DHTML is being discussed, and therefore this is referred to as a positioned element. The next chapter will show how this applies to all elements, not just those that are positioned.
- PositionedElement A div (or span) element that has been absolutely positioned using stylesheets - Referred to using any of - document.getElementById - document.IdOfElement - document.all - document.layers - as above - - read-only
- bgColor Refers to the default background colour of the element - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.background - positionedElement.style.backgroundColor
- clip If available, this refers to the visible area of the element - - read-only - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.clip
- bottom The distance between the top edge of the element and the start - of the bottom portion of the element that is not visible - in pixels (integer) - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.clip
- left The size of the left portion of the element that is not visible - in pixels (integer) - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.clip
- right The distance between the left edge of the element and the start - of the right portion of the element that is not visible - in pixels (integer) - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.clip
- top The size of the top portion of the element that is not visible - in pixels (integer) - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.clip
- document In layers browsers, this refers to the contents of the element, equivalent to a whole new document - (see window.document for what properties will be available) - In many other browsers (such as Opera), this is a reference to window.document - - read-only
- id Refers to the id of the element - In layers browsers, if the name attribute is set, this will be the name attribute and the name attribute must be used instead when referring to the element - For this reason, it is best not to set the name attribute - - read-write
- innerHTML Refers to the contents of the element - as part of the main document - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.document.open, write, writeln and close
- left If available, this is an integer specifying the left coordinate of the element - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.left - positionedElement.style.pixelLeft (not required)
- name Refers to the name of the element - In layers browsers, if the name attribute is set, the positionedElement.id will be the name attribute and the name attribute must be used instead when referring to the element - For this reason, it is best not to set the name attribute - - read-only
- style If available, this refers to the style of the element - - read-only
- background Refers to the default background colour of the element - Browsers other than Opera 5.x may also give other information, eg. background images etc. - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.bgColor - positionedElement.style.backgroundColor
- backgroundColor Refers to the default background colour of the element - - read-write - - Non-layers browsers only (not available in Opera 5.x) - For cross-browser scripting, see also - positionedElement.bgColor - positionedElement.style.background
- clip Refers to the coordinates of the visible area of the element - in string format: - rect(topPos, rightPos, bottomPos, leftPos) - All values should be in pixels (for compatibility reasons) - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - children of positionedElement.clip
- color Refers to the default colour of the text in the element - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.document.fgColor
- height Refers to the height of the element - In the format '100px' - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.resizeTo - positionedElement.pixelHeight
- left Refers to the left coordinate of the element - In the format '100px' - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.left - positionedElement.style.pixelLeft (not required)
- pixelHeight Refers to the height of the element - In pixels as an integer - - read-write - - Internet Explorer compatible only - For cross-browser scripting, see also - positionedElement.resizeTo - positionedElement.style.height
- pixelLeft Refers to the left coordinate of the element - In pixels as an integer - - read-write - - Internet Explorer compatible only - For cross-browser scripting, see also - positionedElement.left - positionedElement.style.left
- pixelTop Refers to the top coordinate of the element - In pixels as an integer - - read-write - - Internet Explorer compatible only - For cross-browser scripting, see also - positionedElement.top - positionedElement.style.top
- pixelWidth Refers to the width of the element - In pixels as an integer - - read-write - - Internet Explorer compatible only - For cross-browser scripting, see also - positionedElement.resizeTo - positionedElement.style.width
- top Refers to the top coordinate of the element - In the format '100px' - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.top - positionedElement.style.pixelTop (not required)
- visibility Refers to the visibility of the element - Available values are 'visible' and 'hidden' - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.visibility
- width Refers to the width of the element - In the format '100px' - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.resizeTo - positionedElement.pixelWidth
- zIndex Refers to the z-index (stacking order) of the element - Must be a positive integer - - read-write - - Non-layers browsers only - For cross-browser scripting, see also - positionedElement.zIndex
- top If available, this is an integer specifying the top coordinate of the element - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.top - positionedElement.style.pixelTop (not required)
- visibility Refers to the visibility of the element - Available values are 'show' and 'hide' - - read-write - - for cross-browser scripting, see also - positionedElement.style.visibility
- zIndex Refers to the z-index (stacking order) of the element - Must be a positive integer - - read-write - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.zIndex
- onclick Fires when the user depresses then releases a mouse button over the positioned element - positionedElement.onclick = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- ondblclick Fires when the user depresses then releases a mouse button twice - in quick succession over the positioned element - positionedElement.ondblclick = functionName; - Old Mac browsers (as well as a few others) generally do not detect this event - It is possible to emulate this event's response using a combination - of onclick and window.setTimeout - - Layers browsers will require you to use captureEvents first - - read-write
- onkeydown Fires when the user presses a key down while the positioned element (but not an input) has the focus - positionedElement.onkeydown = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onkeypress Fires when the user presses and releases a key down while - the positioned element (but not an input) has the focus - positionedElement.onkeypress = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onkeyup Fires when the user releases a key while the positioned element - (but not an input) has the focus - positionedElement.onkeyup = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmousedown Fires when the user depresses a mouse button over the positioned element - positionedElement.onmousedown = functionName; - - Layers browsers will require you to use captureEvents first - - read-write - - Returning false from a right button mousedown will prevent the right click menu from appearing in some browsers - Some may need you to return false from an oncontextmenu event and some do not detect right clicks
- onmousemove Fires when the user moves the mouse while it is over the positioned element - positionedElement.onmousemove = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmouseout Fires when the user moves the mouse from over the positioned element to off the positioned element - positionedElement.onmouseout = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmouseover Fires when the user moves the mouse from off the positioned element to over the positioned element - positionedElement.onmouseover = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- onmouseup Fires when the user releases a mouse button over the positioned element - positionedElement.onmouseup = functionName; - - Layers browsers will require you to use captureEvents first - - read-write
- captureEvents(Event.EventType) Causes layers browsers to react to events - See window.Event for what events can be captured
- resizeTo(int width,int height) Resizes the layer by changing the values of clip.bottom and clip.right - - Layers browsers only - For cross-browser scripting, see also - positionedElement.style.width and positionedElement.style.height - positionedElement.style.pixelWidth and positionedElement.style.pixelHeight
Event objects
- window.event or first argument passed to handler function Holds records of mouse buttons or keys that triggered the event - - Available if triggered by: - object.onEventName = handlerFunctionName; - or - <element onEventName="thisIsEquivalentToAHandlerFunction;"> - - read-write
- altKey Boolean: says if the Alt key was pressed during the event - Note: some browsers do not provide this or the layers - compatible method of checking these keys - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - eventObject.modifiers
- button If a left mouse button triggered the event, this will be 0 or 1 - If a right mouse button triggered the event, this will be 2 - Some browsers do not detect right-clicks - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - eventObject.which
- clientX If the mouse triggered the event, this holds the horizontal position of the mouse - Position is relative to the displayed portion of the page - Three old browsers provide this is relative to the whole page - Current releases of these browsers support it correctly - See the chapter on 'Event information' for more details - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - eventObject.pageX
- clientY If the mouse triggered the event, this holds the vertical position of the mouse - Position is relative to the displayed portion of the page - Three old browsers provide this is relative to the whole page - Current releases of these browsers support it correctly - See the chapter on 'Event information' for more details - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - eventObject.pageY
- ctrlKey Boolean: says if the Ctrl key was pressed during the event - Note: some browsers do not provide this or the layers - compatible method of checking these keys - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - eventObject.modifiers
- keyCode A number that represents the key pressed - Keypad codes may vary - - read-only - - Non-layers browsers only - For cross-browser scripting, see also - eventObject.which
- modifiers A number that represents the combination of special keys pressed during the event - 1 = Alt, 2 = Ctrl, 4 = Shift, 8 = Command (MAC) - Can be added together if combinations are pressed - Note: some browsers do not provide this or the alternative method - of checking these keys - - read-only - - Layers browsers only - For cross-browser scripting, see also - eventObject.altKey - eventObject.ctrlKey - eventObject.shiftKey
- pageX If the mouse triggered the event, this holds the horizontal position - of the mouse relative to the whole page - - read-only - - Netscape and DOM compatible browsers only - For cross-browser scripting, see also - eventObject.clientX
- pageY If the mouse triggered the event, this holds the vertical position - of the mouse relative to the whole page - - read-only - - Netscape and DOM compatible browsers only - For cross-browser scripting, see also - eventObject.clientY
- screenX If the mouse triggered the event, this holds the horizontal position - of the mouse relative to the screen - - read-only
- screenY If the mouse triggered the event, this holds the vertical position - of the mouse relative to the screen - - read-only
- shiftKey Boolean: says if the Shift key was pressed during the event - Note: some browsers do not provide this or the layers - compatible method of checking these keys - - read-only - - Non-layers compatible browsers only - For cross-browser scripting, see also - eventObject.modifiers
- target Refers to the object that triggered the event - irrespective of capturing or bubbling - - read-only - - Netscape and DOM compatible browsers only - For cross-browser scripting, see also - eventObject.srcElement
- this The word 'this' when written as part of the handler function code - refers to the object that triggered the event - With capturing or bubbling, 'this' will refer to each element in turn - Netscape and DOM compatible browsers only - - read-only
- type A string giving the type of event that was triggered - this will be in lower case, without the 'on' - eg. mouseover - In KHTML 2 browsers, this will be prefixed with 'khtml_' for key events - - read-only
- srcElement Refers to the object that triggered the event - irrespective of capturing or bubbling - - read-only - - Internet Explorer compatible browsers only - For cross-browser scripting, see also - eventObject.target
- which If a left mouse button triggered the event, this will be 1 - If a right mouse button triggered the event, this will be 3 - Some browsers do not detect right-clicks - - If a key triggered the event, this will be the key code (keypad codes may vary) - - read-only - - Netscape compatible browsers only - For cross-browser scripting, see also - eventObject.keyCode - eventObject.button
Intrinsic objects showing constructors
The constructors are all properties of the window object but they are almost always used without 'window.'. Syntax:
var variableName = new intrinsicObjectConstructor(options);
For example:
var myArray = new Array('here','there','everywhere');
Array
- Array([int length]) (not in JavaScript 1.2)
Array([element 0[, element 1[, element ... n]]])
[element 0, element 1, element ... n] A variable containing any number of variables within it - Reverses and sorts work only on numerically indexed arrays - - read-write- length The number of cells in a numerically indexed array - - read-write
- concat(elementToAdd[,elementToAdd[,elementToAdd[,etc.]]]) Adds cells to the end of the array containing the specified values - If elementToAdd is an array, its cells are concatenated separately as cells of the array - Returns the new array with the cells added to it
- join([string separatorToReplaceComma]) Returns a string representation of the array with the cell - contents separated by the specified string (default is ',')
- pop() Returns the contents of the last cell from the array - The array is then shortened so that it no longer contains that cell - - Not supported in IE 5.2- Win/Mac
- push(elementToAppend) Adds elementToAppend to the end of the array - - Not supported in IE 5.2- Win/Mac - - It is more efficient and compatible to use: - Array[Array.length] = elementToAppend
- reverse() Reverses the order of the cells in the array
- shift() Returns the contents of the first cell from the array - The array is then shortened so that it no longer contains that cell - The indexes of all other cells are decremented accordingly - - Not supported in IE 5.2- Win/Mac
- slice(int offsetFromStart[,int offsetToEnd]) Returns an array with the cells taken away from the specified portion of the array - If indexToEnd is negative, it is taken as an offset from the end - If it is omitted, then it is assumed to be Array.length
- sort([function sortFunction]) Sorts the array in order of the values of its cells unless sortFunction is specified - sortFunction must accept two arguments - If the function returns > 0, the second argument will be sorted higher than the first - If the function returns < 0, the second argument will be sorted lower than the first - If the function returns 0, the entries will remain as they are with respect to each other
- splice(int offsetFromStart,int numberToRemove[,elementToAdd[,elementToAdd[,etc.]]]) Removes the specified number of cells from the array, - starting at the specified offset - Optionally adds the new elements as cells in the position where - the earlier cells were removed from - The number of cells added does not have to match the number of cells removed - (but it is generally more efficient if they are the same) - Returns an array containing the cells that were removed - - Not supported in IE 5.2- Win/Mac
- toString() or valueOf() Returns a string representation of the array
- unshift(elementToAppend) Adds elementToAppend to the start of the array, and - increments the indexes of all other cells accordingly - - Not supported in IE 5.2- Win/Mac
Boolean
- Boolean([bool value])
true or false A true or false value - - read-write- toString() Returns the word true or false
- valueOf() Returns the boolean value
Date
Note, a UNIX timestamp (milli) is the number of milliseconds since 00:00:00.000 01/01/1970.
Note also that UTC is the time as it would be in the GMT timezone, so GMT and UTC are equivalent.
- Date()
Date(int UNIXTimestampMilli)
Date(year, month, date[, hours[, minutes[, seconds[,ms]]]]) A variable containing a date in several representations - - read-write- getDate() Returns the day of the month represented by the date object
- getDay() Returns the day of the week represented by the date object
- getFullYear() Returns the year represented by the date object in 4 digit format - Not supported by old browsers - See getYear()
- getHours() Returns the hour represented by the date object in 24 hour format
- getMilliseconds() Returns the millisecond represented by the date object
- getMinutes() Returns the minute represented by the date object
- getMonth() Returns the month represented by the date object (0-11)
- getSeconds() Returns the second represented by the date object
- getTime() Returns the UNIX timestamp (in milliseconds) represented by the date object
- getTimezoneOffset() Returns the number of hours the user's computer is away from GMT
- getUTCDate() Returns the day of the month represented by the date object converted to GMT
- getUTCDay() Returns the day of the week represented by the date object converted to GMT
- getUTCFullYear() Returns the year represented by the date object in 4 digit format converted to GMT
- getUTCHours() Returns the hour represented by the date object in 24 hour format converted to GMT
- getUTCMilliseconds() Returns the millisecond represented by the date object converted to GMT
- getUTCMinutes() Returns the minute represented by the date object converted to GMT
- getUTCMonth() Returns the month represented by the date object converted to GMT
- getUTCSeconds() Returns the second represented by the date object converted to GMT
- getYear() Returns the year represented by the date object - This could be in a variety of formats depending on the browser - As JavaScript does not support dates before 1970 or beyond 2038 anyway, the following algorithm solves all problems - - theYear = dateObject.getYear() % 100; //0-38 or 70-99 - theYear += ( theYear < 39 ) ? 2000 : 1900; //1970-2038 - - or - - theYear = ( dateObject.getYear() % 100 ) + ( ( ( dateObject.getYear() % 100 ) < 39 ) ? 2000 : 1900 );
- setDate(int dayOfMonth) Sets the day of the month represented by the date object (0-11)
- setFullYear(int yearIn4DigitFormat[,int month[,int dayOfMonth]]) Sets the year represented by the date object in 4 digit format
- setHours(int hours[,int minutes[,int seconds[,int milliseconds]]]) Sets the hour represented by the date object in 24 hour format
- setMilliseconds(int milliseconds) Sets the millisecond represented by the date object
- setMinutes(int minutes[,int seconds[,int milliseconds]]) Sets the minute represented by the date object
- setMonth(int month[,int dayOfMonth]) Sets the month represented by the date object
- setSeconds(int seconds[,int milliseconds]) Sets the second represented by the date object
- setTime(int UNITXTimestampMilli) ets the UNIX timestamp (in milliseconds) represented by the date object
- setUTCDate(int UNITXTimestampMilli) Sets the day of the month represented by the date object converted to GMT
- setUTCFullYear(int yearIn4DigitFormat[,int month[,int dayOfMonth]]) Sets the year represented by the date object in 4 digit format converted to GMT
- setUTCHours(int hours[,int minutes[,int seconds[,int milliseconds]]]) Sets the hour represented by the date object in 24 hour format converted to GMT
- setUTCMilliseconds(int milliseconds) Sets the millisecond represented by the date object converted to GMT
- setUTCMinutes(int minutes[,int seconds[,int milliseconds]]) Sets the minute represented by the date object converted to GMT
- setUTCMonth(int month[,int dayOfMonth]) Sets the month represented by the date object converted to GMT
- setUTCSeconds(int seconds[,int milliseconds]) Sets the second represented by the date object converted to GMT
- setYear(int numberOfYearsSince1900) Sets the difference between 1900 and the year represented by the date object
- toUTCString or toGMTString() Returns the date as a string, converted to GMT
- toString or toLocaleString() Returns the date as a string
- valueOf() Returns the UNIX timestamp (in milliseconds) represented by the date object
Function
- Function([string varName,[string varName2,[etc.]]]string scriptToEvaluate)
function functionName(listOfVariables) { function code }
functionName = function (listOfVariables) { function code } A series of instructions that can be activated as and when necessary - Can return values - - read-write- caller Refers to the function that called this function (or null if none) - Note, it is a property of the individual function and must be written as - functionObject.caller - - Warning, this property is non-standard and is not available in many browsers, including - Opera, Safari 2-, Konqueror 3.5.6-, NetFront, ICEbrowser, Escape and Clue - - Do not use this property - - read-write but unusable if written to
- prototype If the function is used as an object constructor; - functionObject.prototype.newPropertyName - creates new properties for all objects of that class - - read-write but unusable if written to
- this 'this' written as part of the function code refers to the current object - If activated directly by an event, this will be the object that triggered the event - If being used to construct an object, this will refer to the construct object - (that is the instantaneous object being constructed, which is stored temporarily until it is returned) - If neither of these are satisfied, this refers to window - 'this' is an instantaneous variable, and is not a property of the function - - read-only
- arguments[] The arguments collection when written as part of the function code - refers to the collection of variables passed to the function - Note, it is a property of the individual function but can be written as - either functionObject.arguments or just arguments - - read-write but unusable if written to
- callee A reference to the function that this code is running inside - Not supported by WebTV/MSNTV - - read-write but unusable if written to
- apply(object: thisObject[,array: arguments]) Runs the function as if it were a method of the thisObject - passing it the arguments from the arguments parameter - - Not supported in IE 5.2- Win/Mac, WebTV/MSNTV, or early Netscape 4 versions
- call(object: thisObject[,argument[,argument[,etc.]]]) Runs the function as if it were a method of the thisObject - passing it the separate arguments from the subsequent parameters - - Not supported in IE 5.2- Win/Mac, WebTV/MSNTV, or early Netscape 4 versions
- toString() Returns a string representation of the function - - In theory, for user-defined functions, the string should - be valid function code (with anonymous function braces) - However, most browsers will have problems with certain - constructs, and browsers on devices with limited memory - may not provide anything at all
- valueOf() Returns the function
Image
- Image([int width,int height]) Creates an image that is not displayed but is stored in cache - Children as for window.document.nameOfImage - The image will not be loaded until the src is set - - read-write
Number
- Number(numberOrString value)
number in hex, octal or decimal A variable with a numerical value - Can be negative or positive or NaN or Infinity and can have E+ or E- - - read-write- toFixed(precision) Returns the number as a string, rounded and formatted - with the given number of decimal places - Not supported in most old browsers, including IE 5.0- - Most non-IE browsers return large numbers in scientific - notation
- toPrecision(precision) Returns the number as a string, reduced to a precision of the - given number of decimal places - May be returned in scientific notation - Not supported in most old browsers, including IE 5.0-
- toExponential(precision) Returns the number as a string, rounded and formatted - in scientific notation with the given number of digits after - the decimal point - Not supported in most old browsers, including IE 5.0-
- toLocaleString() Returns the number as a string, - formatted according to the user's locale - Not supported in most old browsers
- toString() Returns the number as a string
- valueOf() Returns the number
Object
- Object()
{ propertyName1: value1[, propertyName2: value2[, etc.]] } Creates a variable that can have properties or child objects - - read-write- constructor Returns a reference to the function that is used as a constructor for this class of object
- hasOwnProperty(string propertyName) Returns true if the given property is attached directly to the object instance
- toString() Returns a string representation of the object - (typically [object Object])
- valueOf() Returns a string representation of the object - (typically [object Object])
Option
- Option([string text,string value[,bool selected]]) Creates an select input option that can be stored until it is inserted into a select input using: - window.document.nameOfForm.nameOfSelect.options[int optionNum] = optionObject - Children as for window.document.nameOfForm.nameOfSelect.options[int optionNum] - - read-write
Regular Expression
- RegExp(string pattern,string options)
/pattern/options A text pattern matching series of meta and normal characters - Some old browsers fail to implement this correctly (eg. Opera 6- and iCab 2-) - - read-write- compile(string pattern,string options) Redefines the regular expression and compiles it for faster use than normal - Only useful if using the same regular expression multiple times - Redundant in current browsers; do not use it
- exec(string stringToMatch) Attempts to match the regular expression against the string - Returns an array of the details of the last match or null if none: - - [ - last substring that fully matched the regular expression, - last instance of first capture, - ..., - last instance of ninth capture - ] - - Returned array has two other properties: - index - the position within the string where the pattern began to match (read-only) - input or $_ - the original string (read-only)
- global Boolean: says if the 'g' option was used for a global match - - read-only
- ignoreCase Boolean: says if the 'i' option was used to ignore case - - read-only
- lastIndex The index where the last match occurred during exec or test (read) - OR - The index at which to start the next match (write)
- source The text of the pattern - - read-only
- test(string stringToMatch) Attempts to match the regular expression against the string - Returns boolean if a match is found
String
- String([stringOrObjectToBeRepresentedAsString])
'content'
"content" A variable consisting only of characters - These can come from any character set supported by the current document - - read-write- length The number of characters in the string - - read-write
- anchor(string nameOfAnchor) Surrounds the string with <a name="nameOfAnchor"> tags - - For use when dynamically generating page content - Use ID attributes instead
- big() Surrounds the string with <big> tags - - For use when dynamically generating page content - There is almost always a more appropriate element you can use
- blink() Surrounds the string with <blink> tags - - For use when dynamically generating page content - This element is non-standard (and annoying), do not use it
- bold() Surrounds the string with <b> tags - - For use when dynamically generating page content - You may want to use <strong> instead
- charAt(int index) Returns the character at the specified index
- charCodeAt(int index) Returns the numerical value of the character at the specified index
- concat(string stringToAppend[,string stringToAppend[,string stringToAppend etc.]]) Returns the strings appended to each other and the string object in order
- fixed() Surrounds the string with <tt> tags - - For use when dynamically generating page content - There is almost always a more appropriate element you can use - (<code>, <samp> or <var>)
- fontcolor(string colorValue) Surrounds the string with <font color="colorValue"> tags - - For use when dynamically generating page content - This element is deprecated, do not use it
- fontsize(int size) Surrounds the string with <font size="size"> tags - - For use when dynamically generating page content - This element is deprecated, do not use it
- indexOf(string searchString[,int offset]) Returns the first position of the searchString within the string object - Returns -1 if none
- italics() Surrounds the string with <i> tags - - For use when dynamically generating page content - You may want to use <em> instead
- lastIndexOf(string searchString[,int offset]) Returns the last position of the searchString within the string object - Returns -1 if none
- link(string hrefToLinkTo) Surrounds the string with <a href="hrefToLinkTo"> tags - - For use when dynamically generating page content
- match(RegExp searchExpression) If the regular expression does not have the global flag, it - returns an array containing the part of the string that matched - the expression, followed by every capture from the regular - expression in sequence, from the first match within the string - - If the regular expression does have the global flag, it returns - an array containing every match of the entire regular - expression against the string - - If there are no matches, it returns null - - The first 9 captures/matches of the regular expression are - also stored in the global RegExp object
- replace(RegExp searchExpression,string replacementText) Replaces the first occurrence of the specified regular - expression within the string with the replacement text
- search(RegExp searchExpression) Returns the first position of the regular expression within the string object - Returns -1 if none
- slice(int offsetFromStart[,int offsetFromEnd]) Returns the substring starting at the specified index and ending - at the specified offset from the end - If the offset is not specified, the offset is taken as 0
- small() Surrounds the string with <small> tags - - For use when dynamically generating page content - There is almost always a more appropriate element you can use
- split(RegExp separator[,int maxArrayLength]) Splits a string on the occurrence of a specified substring - Results are returned as an array - If a maximum length is specifed, the final cell will contain any amounts - not split after that point
- strike() Surrounds the string with <s> tags - - For use when dynamically generating page content - This element is deprecated, do not use it - Usually, the <del> element is what you want to use
- sub() Surrounds the string with <sub> tags - - For use when dynamically generating page content
- substr(int startIndex[,int length]) Returns the substring starting at the specified index and the specified length long - If no length is specified, the length is to the end of the string
- substring(int startIndex,int endIndex) Returns the substring starting at the specified index and ending at the specified index
- sup() Surrounds the string with <sup> tags - - For use when dynamically generating page content
- toLowerCase() Returns the string in lower case
- toUpperCase() Returns the string in upper case
- valueOf() Returns the string
Last modified: 1 April 2011