CONTENTS |
THIS GLOSSARY IS FOR A QUICK LOOK-UP of different keywords, statements, and terms used in standard ECMA-262 JavaScript, with clear examples provided. You will not find words that either Microsoft or Netscape developed outside the ECMA-262 standard, no matter how helpful these terms are. Also, you will not find a standard "Reference" section here. If that's what you want, you can find the mother of all JavaScript references at http://developer.netscape.com/evangelism/docs/reference/ecma/Ecma-262.pdf.
The European Computer Manufacturer's Association (ECMA) is the definitive authority on JavaScript, and its 188-page reference section includes all of the technical material about JavaScript. (See also http://www.ecma.ch.)
This glossary's function is to make it easy to find a term, see what it does, and see an example of how to write it. It's quick and simple, and it will help you get a statement correctly written. To keep this glossary clear, the examples are short and to the point, and the definitions are nontechnical but functional. Some examples are shorter than others, depending on what you need to use them effectively. Objects and their methods are listed by the nature of the object and are followed by a property or method. For example, the string object (which is almost never called "string") will include string.length. Typically, the length of a string will be found in an iterative loop such as this:
for(counter=0;counter < cusName.length; counter++) {....
The string's name is cusName, which is a far more likely string name than string. However, to make it simple to find what properties and methods are associated with strings, I use string.xxxx to make it simple to find things alphabetically in the glossary. Moreover, some properties and methods are part of an object of an object. For example, form has several different associated elements, such as Input, so you will see "formInput.text" and "formInput.button" entries because they are all types of <input> options. Also, several objects have similar or identical properties. For example, you will find "history.length" and "array.length" entries, among others. So, to help keep things clear, it makes more sense to alphabetize the objects using clear names rather than the properties or methods that might occur in several different objects.
Opens an alert box on the screen in the browser.
Example:
var fname="Linda" alert("Hello " + fname)
Creates an anchor in a document.
Example:
var fish = "trout" document.write(fish.anchor("fresh_water"))
An applet in the current HTML page. May be expressed as a name or an array.
Example:
document.applets[3].hide( )
A multielement array object. The keyword Array( ) is a constructor object. Optionally, you can enter the number of array elements.
Example:
var group=new Array(5); var gang = new Array("Fuzzy", "Willie", "Sleepy", "Homer")
Adds new elements that do not become a permanent part of the array.
Example:
var dogs = new Array("Rottie", "Sheltie") dogs.concat("Swissy", "Beagle") alert(dogs.concat("Swissy", "Beagle")) //Output = Rottie, Sheltie, Swissy, Beagle
Elements in an array are made into a single concatenated string with an optional separator.
Example:
var dogs = new Array("Rottie", "Sheltie") alert(dogs.join(" ")) //Output = Rottie Sheltie
Returns the length of an array.
Example:
var cities = new Array ("Paris", "London", "Los Angeles", "Bloomfield"); var nCities = cities.length; //nCities = 4
Reverses the order of elements in an array.
Example:
var geekLetters = new Array("alpha", "beta", "gamma"); alert(geekLetters.reverse( )); //Output = gamma, beta, alpha
Returns a segment of an array beginning with s and ending with e.
Example:
var cities = new Array ("Paris", "London", "Los Angeles", "Bloomfield"); var nCities = cities.splice(1,2); alert(nCities) //Output= London, Los Angeles
Puts array elements into alphabetical order.
Example:
var cities = new Array ("Paris", "London", "Los Angeles", "Bloomfield"); var nCities = cities.sort( ); //nCities = Bloomfield,London, Los Angeles, Paris
Converts all array elements to a single string.
Example:
var deli = new Array ("Bagels", "Lox", "Dill Pickles", "Cream Cheese"); var food = deli.toString( ); // food = single string Bagels,Lox,Dill Pickles,Cream Cheese
Date and time object.
Example:
var today=new Date( ); document.write(today); //Screen shows: Sat Jul 28 10:52:44 GMT-0400 (2001)
Day of the month, as a number between 1 and 31.
Example:
var today=new Date( ); alert(today.getDate( )); //Value between 1 and 31
Day of the week, expressed as a value 0 to 6, with Sunday being 0.
Example:
var today=new Date( ); alert(today.getDay( )); //Value between 0 and 6
Returns the current year.
Example:
var today=new Date( ); alert(today.getFullYear( )); //Actual year such as 2003
Returns 24 hours, from 0 to 23 (midnight is 0).
Example:
var today=new Date( ); alert(today.getHours( )); //2 PM returns 14
Returns 0 to 999 in milliseconds.
Example:
var today=new Date( ); var now = today.getMilliseconds( ) document.write(now); //Enter script and press Re-load on browser to see changes
Gets the current minute of the hour, between 0 and 59.
Example:
var today=new Date( ); var now = today.getMinutes( ) document.write(now);
Gets the current month, from 0 to 11 (January is 0).
Example:
var today=new Date( ); var now = today.getMonth( ) document.write(now);
Returns the current seconds, 0 to 59.
Example:
var today=new Date( ); var now = today.getSeconds( ) document.write(now);
The time between the Date( ) value and January 1, 1970.
Example:
var today=new Date(); var now = today.getTime( ) document.write(now); //Some value like 996335075147 appears
The difference, in minutes, in local time and UTC (universal time, or Greenwich Mean Time).
Example:
var today=new Date( ); var now = today.getTimezoneOffset( ) document.write(now/60); //Shows difference in hours because to division by 60.
Returns the UTC day of month (1 31).
Example:
var today=new Date( ); var now = today.getUTCDate( )
Returns the UTC day of week (0 6).
Example:
var today=new Date( ); var now = today.getUTCDay( )
Returns the UTC year (such as 2003).
Example:
var today=new Date( ); var now = today.getUTCFullYear( )
Returns UTC hours (0 23).
Example:
var today=new Date( ); var now = today.getUTCHours( );
Returns milliseconds of a UTC date.
Example:
var today=new Date( ); var now = today.getUTCMilliseconds( )
Returns UTC minutes (0 59).
Example:
var today=new Date( ); var now = today.getUTCHours( );
Returns the UTC month (0 11).
Example:
var today=new Date( ); var now = today.getUTCMonth( );
Returns UTC seconds (0 59).
Example:
var today=new Date( ); var now = today.getUTCSeconds( );
This function contains bugs. Use getFullYear( ) instead.
Sets the day of the month between 01 and 31. (It does not change your computer's internal clock.)
Example:
var today=new Date( ); today.setDate(31); var myTime=today.getDate( ); //myTime = 31 no matter what the day is
Sets the year to a specified year.
Example:
var today=new Date( ); var now=today.getFullYear( ); today.setFullYear(1992); alert("That was " + (now - today.getFullYear()) + " years ago." );
Sets the hours of the day from 0 to 23.
Example:
var today=new Date( ); today.setHours(15); document.write(today.getHours( ));
Sets m to an integer between 0 and 999. (Values greater than 999 reduce to the three rightmost values; 5432 reverts to 432.)
Example:
var today=new Date( ); today.setMilliseconds(999); document.write(today.getMilliseconds( ));
Sets minutes between 0 and 59.
Example:
var today=new Date( ); today.setMinutes(43); document.write(today.getMinutes( ));
Sets the month, between 0 and 11.
Example:
var today=new Date( ); today.setMonth(5); //Sets June document.write(today.getMonth( ));
Sets seconds, between 0 and 59.
Example:
var today=new Date( ); today.setSeconds(54); document.write(today.getSeconds( ));
Sets the time in milliseconds relative to January 1, 1970.
Example:
var today=new Date( ); today.setDate(996338910155); //Sets July 28, 2001
Sets the UTC day of the month (1 31).
Example:
var today=new Date( ); today.setUTCDate(22); document.write(today.getUTCDate( ));
Sets the UTC full year (such as 2020).
Example:
var today=new Date( ); today.setUTCFullYear(2002)
Sets UTC hours (0 23).
Example:
var today=new Date( ); today.setUTCHours(17)
Sets UTC milliseconds (0 999).
Example:
var today=new Date( ); today.setUTCMilliseconds(999); document.write(today.getUTCMilliseconds( ));
Sets minutes from 0 to 59.
Example:
var today=new Date( ); today.setUTCMinutes(45);
Sets UTC months from 0 to 11.
Example:
var today=new Date( ); today.setUTCMonth(5);
Sets UTC seconds from 0 to 59.
Example:
var today=new Date( ); today.setUTCSeconds(5);
Conversion of date to string.
Example:
var today=new Date( ); var ls=today.toLocaleString( ); document.write(ls); //formatted as Jul 28 14:59:29 2001
Conversion of date to string. Note differences in format between toString( ) and toLocaleString( ).
Example:
var today=new Date( ); var ls=today.toString( ); document.write(ls); //formatted as Sat Jul 28 15:03:55 GMT-0400 (2001)
Conversion of data to a UTC string.
Example:
var today=new Date( ); var ls=today.toUTCString( ); document.write(ls); //formatted as Sat, 28 Jul 2001 19:06:12 GMT
Date converted to a number.
Example:
var today=new Date( ); var ls=today.valueOf( ); document.write(ls);
A web (HTML) page. References to the document object are to its properties and methods. It may also be referenced as part of a window.
Example:
window.document
Color when link is selected.
Example:
document.alinkColor="green";
Anchors in the current document as the named object or element.
Example:
var alpha=document.anchor[4]
Reference to applets in the current document as a named object or element.
Example:
var alpha=document.applets[0]
Background color of a page.
Example:
document.bgColor="'#ff00ff"
Closes an open document when writing HTML code using JavaScript.
Example:
document.close( )
The cookie on an HTML page.
Example:
var crumbs = document.cookie; //Read value of cookie into variable "crumbs"
Specifies the domain from which one window can read another window.
Example:
document.domain="sandlight.com";
Array of objects of data embedded in an HTML page.
Example:
var embedBugs = document.embeds.length
A document's default text color.
Example:
document.fgColor="cornflowerblue";
The form object of an HTML page. All forms constitute elements of a form's array object.
Example:
document.forms[0].reset( );
The image object of an HTML page. All images on the page are part of the image object array.
Example:
var sizeImages=document.images.length;
Date of last modification.
Example:
var fixUp = document.lastModified; document.write("Last modified by Al => " + fixUp);
Sets unvisited link color.
Example:
document.linkColor="peru"
An HTML page's link array object. (Properties of a page's links can be displayed after a page is fully loaded.)
Example:
function showMe( ) { var alpha=document.links.length; alert(alpha); }
Access URL.
Example:
document.location="http://www.sandlight.com"; //link to www.sandlight.com
Opens a new document. Typically used for writing HTML pages from script in JavaScript.
Example:
document.open( );
The page that linked to the current page. Requires a link from a previous page.
Example:
var homie = document.referer; document.location=homie;
Current HTML page's title.
Example:
alert(document.title);
URL of specified page. (Replaces document.location.)
Example:
Document.URL="http://www.sandlight.com"
Specifies the color of visited links.
Example:
document.vlinkColor="#ff00ff";
Used for both sending text to a page and writing an HTML document.
Example:
document.write("<b>'This is bold' </b>");
Same as document.write, with an added carriage return.
Example:
document.writeln("This is the first line.") document.writeln("This is on another line.")
Codes string for sending in a form or email.
Example:
var alpha="Happy Birthday, Pat"; var sendMe=escape(alpha); document.write(sendMe); //Returns = Happy%20Birthday%2C%20Pat
Evaluates an expression and puts it into a string.
Example:
var alpha=eval(Math.sqrt(16)); alert(alpha); //Output = 4
Input form treated as an array object in JavaScript.
Example:
document.forms[2].reset( )
All of the input and textarea elements in a form container. Each is treated as an element of form array object and is addressed by element name or number.
Example:
var output = document.forms[0].elements[2].value; var output = document.customers.lastNames.value;
The numbers of elements in a form container.
Example:
var howLong = document.forms[3].length;//Number of elements in form. var myForm = document.forms.length; //Number of forms in document
Clears all data from a form.
Example:
Function clearEm( ) { document.forms[0].reset( ); }
Current value of a Reset button. The value is placed in an <input> tag.
Example:
var alpha=document.forms[0].wipe.value; //wipe is name of reset button
Returns the contents of a textarea.
Example:
var Texas = document.forms[0].fred.value; //The text area's name is "fred." //The variable Texas contains the contents of the textarea //named "fred."
Returns or changes value assigned to a button.
Example:
var button = document.forms[0].butNow.value; //Returns the name on the button!
Generates a Boolean value on whether a check box is checked.
Example:
//Checkbox object named "chuck" if (document.forms[0].chuck.checked) {....
Boolean read-only to determine whether a check box is initially checked.
Example:
var alpha = document.forms[0].chuck.defaultChecked; if(alpha) { alert("It's checked from the beginning.") }
Returns on unless a specific value is assigned in the Value attribute in the <input> container.
Example:
var alpha = document.forms[0].chuck.value
Returns the name of a form element.
Example:
var alpha=document.forms[0].elements[4].name; //Places the name of the fifth element into alpha
The value of a password, as defined in the value attribute of the form element.
Example:
var openUp = document.forms[0].elements[4].value; if(openUp=="reallySecret") {....
A Boolean value to determine whether a radio button is checked.
Example:
var alpha=document.forms[0].elements[2].checked; if(alpha) { alert(":It's checked"); } //elements[2] is one of three radio buttons
The value of the value attribute is assigned in the <input> tag in the HTML page. If no value is assigned, the value returned is on, whether the button is checked or not. While all the names of radio buttons in a form should be the same, the values are typically different.
Example:
var alpha=document.forms[0].elements[3].value; //elements[3] is a radio button input element
The value of the Submit button assigned in the <input> tag, or Submit Query if no value is assigned.
Example:
var alpha=document.forms[0].jack.value; //"jack" is the name of the submit button.
The current value of a text field or a value to be assigned.
Example:
var alpha=document.forms[0].announce.value; alpha = "Read this."; //String assigned to text field "announce".
Returns select-one or select multiple, depending on the contents of the <select> tag.
Example:
var alpha=document.forms[0].nancy.type; alert(alpha); //name is the select element's name.
The value of a form input element.
Example:
var fullName=document.forms[0].name.value;
Clears all text forms.
Example:
<body onLoad=document.forms[0].reset( )
The length refers to the number of options in a select property.
Example:
var numOps=document.forms[0].chooser.length; alert("You have " + numOps + " options."); //"chooser" is the name of the select form element.
Options properties in a select object.
Example:
var selections=document.forms[0].chooser; var selOp=selections.options.length;
Element value of the selected option.
Example:
var selections=document.forms[0].chooser; //chooser is select obj. var selOp=selections.selectedIndex; alert(selOp)//Element value of selected options appears
Either select one or select-multiple types.
Example:
var selections=document.forms[0].chooser; var selType=selections.type alert(selType) //chooser is select object
A delayed operation fired by an event handler.
Example:
function showView(msg) { alert(msg); //Statements go here. } //Function terminated by closing curly brace
Places the ouput of a function into a string format.
Example:
function showMe(msg) { alert(msg) } var buzz=showMe("I am a function").toString; alert(buzz);
Goes to the previously visited URL that was viewed before the current page in the current session.
Example:
window.history.back( );
Goes to the previously visited URL that was viewed after the current page in the current session.
Example:
window.history.forward( )
Goes forward or backward a specified number of pages. Positive numbers go forward, and negative numbers go backward.
Example:
window.history.go (2) // Two pages forward window.history.go (-3) // Three pages back
Reference to an image in an HTML page. All embedded images are considered part of an image array.
Example:
var tUp=new Image() tUp.src="targetUp.jpg" function showTarget() { document.images[1].src=tUp.src }
Returns the width of the border specified in an <img> tag.
Example:
var bdr=document.images[0].border; alert(bdr); //bdr is the width of the border
Boolean value of whether the browser has completed loading an image.
Example:
var upYet=document.images[1].complete; if(upYet) { alert("Image is loaded"); }
Returns the value of the height HTML attribute.
Example:
var grH = document.flame.height //flame = graphic name attribute in <img> tag.
Returns the number of blank pixels on the left and right of the image.
Example:
var xPixes = document.flame.hspace //flame = graphic name attribute in <img> tag.
Name attribute of an <img> tag.
Example:
//Name in <img> tag is "flower" document.flower
The filename (or URL) of the image to appear in the browser. This can be changed to allow different images to occupy the same position. The first URL is defined in the HTML <img> tag in the SRC attribute.
Example:
var rollin= new Image( ); rollin.src="pix/nextOne.jpg"; document.images[3].src=rollin.src;
Returns the number of blank pixels above and below an image.
Example:
var vPixes = document.flame.vspace //flame = graphic name attribute in <img> tag.
Returns the width of the image set in the <img> tag's Width attribute.
Example:
var w=document.images[0].width;
Returns a Boolean value of whether the number is finite.
Example:
var littleNumber = 123 if(isFinite(littleNumber)) { alert("We can afford it!") }
Returns a Boolean value of whether the value is a number.
Example:
if(isNaN(price) { alert("Your entry is not a number) }
A link in an HTML page. Each link is an element in the links array belonging to the document object.
Example:
function numLinks( ) { var nl = document.links.length; alert("You have " + nl " links in your page."); }
The browser location and a control of that location. Each of the following properties of location make up a part of a complete URL. The following semificticious URL contains all of the properties in location: http://www.sandlight.com:1944/js/seeker.html?script#side.
location.hash #side
location.host www.sandlight.com:1944
location.hostname www.sandlight.com
location.href The entire URL
location.pathname js/seeker.html?script#side
location.port 1944
location.protocol http://
location.search ?script
All of the location properties are read/write and can be used to access any of the properties of the location object.
Reloads the current page.
Example:
Location.reload( )
Replaces the current page with a new page, but without keeping a history.
Example:
location.replace(http://www.sandlight.com)
Math Constants
All math constants have a single value, as noted here. You can place them into variables or use the constants themselves wherever needed. Use the following example format:
var cirArea = Math.PI * (radius * radius)
Table G.1 shows the constants, their meaning, and their value.
Name | Meaning | Value |
---|---|---|
Math.E | Constant e | 2.718281828459045 |
Math.LN10 | Constant loge 10 | 2.302585092994046 |
Math.LN2 | Constant loge 2 | .6931471805599453 |
Math.LOG10E | Constant log10 e | .4342944819032518 |
Math.LOG2E | Constant log2 e | 1.4426950408889634 |
Math.PI | Constant pi | 3.141592653589793 |
Math.SQRT1_2 | Constant 1 divided by the square root of 2 | .7071067811865476 |
Math.SQRT2 | Constant square root of 2 | 1.4142135623730951 |
Math Functions
All built-in JavaScript math functions expect some type of argument, some with a range. However, their format is the same as for math constants and can be placed into variables or objects, as can other functions. Table G.2 provides the basics on math functions.
Name | Meaning | Arguments |
---|---|---|
Absolute value | Math.abs( ) | Any positive or negative number |
Math.acos( ) | Arc cosine | 1.0 to 1.0 |
Math.asin( ) | Arc sine | 1.0 to 1.0 |
Math.atan( ) | Arc tangent | Any positive or negative number |
Math.ceil( ) | Round up number | Any positive or negative number |
Math.cos( ) | Cosine | Any angle measured in radians* |
Math.exp( ) | excomputed | Any expression or value to be used as exponent |
Math.floor( ) | Round down number | Any positive or negative number |
Math.log( ) | Natural logarithm | Any positive value |
Math.max(n1,n2) | Larger of two values | Any two values |
Math.min(n1,n2) | Smaller of two values | Any two values |
Math.pow(n1,n2) | Computes the power of | First value to the power of the second value |
Math.random( ) | Returns a random number | Returns a number between 0.0 and 1.0 |
Math.round( ) | Rounds to the nearest whole | Any value |
Math.sin( ) | Sine | Any angle measured in radians* |
Math.sqrt( ) | Square root | Any positive number |
Math.tan( ) | Tangent | Any angle measured in radians* |
To convert an angle to a radian, use this method:
var radian = angle * (Math.PI * 2) / 360
Browser object (not just Netscape Navigator).
Returns Mozilla for both IE and NN.
Example:
var ncode=navigator.appCodeName alert(ncode) //See Mozilla!
Returns browser name (Microsoft Internet Explorer or Netscape).
Example:
var nName=navigator.appName alert(nName)
Returns the version of the browser. However, both Netscape and Microsoft have version numbers that do not match the version on their browsers. Version 6 of IE returns 4.0, and Version 6.1 of NN returns 5.0. Also returns the encryption and platform.
Example:
var nVer=navigator.appVersion alert(nName)
Checks to see whether Java is enabled in your current browser.
Example:
if(!navigator.javaEnabled( )) { alert("Enable your browser for Java!") }
Returns the platform version (such as Wind32 or MacPPC).
Example:
var nPlat=navigator.platform if(nPlat==Win32) { document.fgcolor="cornflowerblue"; }
Returns a combination of the code name and version (such as Mozilla/5.0 [Macintosh; U; PPC; en-US; rv:0.9.1] Gecko/20010607 Netscape6/6.1b1).
Example:
var uAgnt = navigator.userAgent; alert(uAgnt);
Number Constants
Like the math constants, the number constants have fixed values, even though many of the values must be represented by limit values. Table G.3 shows JavaScript's number constants.
Name | Meaning | Value |
---|---|---|
Number.MAX_VALUE | Largest number possible | 1.7976931348623157e+308 |
Number.MIN_VALUE | Smallest number close to 0 | 5e-324 |
Number.NaN | Not-a-number value | Any non-numeric value |
Number.NEGATIVE_INFINITY | A negative value greater than the highest value that JavaScript can represent | Negative maximum value plus minimum value |
Number.POSITIVE_INFINITY | A positive value greater than the highest value that JavaScript can represent | Positive maximum value plus minimum value |
Number Methods
A single Number method is available in JavaScript.
Converts a number object to a string.
Example:
var valWord=Number.MAX_VALUE; valWord.toString();
A compound data type in which all other objects inherit the behavior of the object.
Example:
var kennel = new Object( ); kennel.Bigdogs = "Large breed dogs." Kennel.Bigdogs.wolf = "Irish Wolfhounds"
A read-only reference to a type of object function used as constructor. For example, if an object is used as a constructor, function Object() is returned; if an array is used, function Array() is returned.
Example:
var kennel = new Object( ); document.write(kennel.constructor) //return function Object( ) { [native code] }
Generally an automatic conversion in JavaScript, the method can clarify conversions.
Example:
var hotel = Excelsior.toString( ) //Excelsior is an existing object alert(hotel)
Returns the object or its primitive value, but usually the object. Typically returns only the object itself. (Rarely used.)
Example:
var showOut = Excelsior.valueOf( ); document.write(showOut) // output=function valueOf( ) { [native code] }
Converts a string to a floating-point number.
Example:
var strNum = "123.45"; var realNum = parseFloat(strNum); //realNum is floating point.
Converts a string to an integer (rounded down).
Example:
var strNum = "123.45"; var intNum = intFloat(strNum);
Returns the vertical screen size in pixels.
Example:
var upScreen = screen.availHeight
Returns the available horizontal screen size in pixels.
Example:
var acrossScreen = screen.availWidth
Returns the number of bits per pixel. Most modern computers provide 32-bit color.
Example:
var colorPix = screen.colorDepth;
Returns the actual height of the screen. (It is different from availHeight in that it includes all space occupied by icon bars.)
Example:
var allScreenHi = screen.height;
Returns the actual width of the screen.
Example:
var allScreenWide = screen.width;
String objects are created using the String( ) constructor.
Example:
var alpha=new String("Testing");
String is output in <big> format.
Example:
var alpha=new String("Testing"); document.write(alpha.big( ));
String is output in <blink> format.
Example:
var alpha=new String("Testing"); document.write(alpha.blink( ));"
String is output in <b> format.
Example:
var alpha=new String("Testing"); document.write(alpha.bold( ));
Returns a character in a string at position p.
Example:
var alpha=new String("willie@harlemHome.org"); for(var counter = 0; counter < alpha.length; counter ++) { if(alpha.charAt(counter) == "@") { var flag=1; } //Sets a flag variable if the @ is found }
Returns the ASCII code of character at position p.
Example:
var alpha = new String("Fancy Characters &%$#@") var asKey = alpha.charCodeAt(19);
Concatenates strings in an argument to a string object.
Example:
var goof = new String("Mo"); var goofs = goof.concat("Larry","Curly","Shep"); document.write(goofs);
Sets font to <TT> style.
Example:
var alpha=new String("Testing"); document.write(alpha.fixed( ));
Assigns a font color to the string.
Example:
var alpha=new String("Color Me!"); document.write(alpha.fontcolor("pink"));
Assigns a font size using HTML's sizing units (1 7).
Example:
var alpha=new String("I'm Big"); document.write(alpha.fontsize(7));
Creates a string from ASCII or Unicode character values.
Example:
var valentine=String.fromCharCode(76,79,86,69); //Note lack of 'new' document.write(valentine);
Locates the first occurrence of substring (s) in a string, with an optional start (st) position. The initial position is 0.
Example:
var alpha="Lots of characters." var sIO = alpha.indexOf("char"); document.write("The substring begins at position " + sIO + "."););
Creates an italicized font.
Example:
var alpha=new String("I\'m from Rome!"); document.write(alpha.italics( ));
Searches for the first occurrence of the substring beginning with the last character. The initial position is 0.
Example:
var alpha="To be or not to be." var lindx = alpha.lastIndexOf("be"); document.write("The last instance of the substring begins at position " + lindx + ".");
Returns the length of the string.
Example:
var myName =new String("Rooty Judy Hooty"); var nameNum =myName.length -2 document.write("Her name is " + nameNum + " characters long.") //Subtracted 2 for spaces;
Creates a link to the specified URL.
Example:
var hookUp =new String("Treasure Island"); document.write(hookUp.link("http://www.sandlight.com"))
Matches a string with one or more regular expressions. (Use Perl regular expression format.)
Example:
var smarties =new String("A generation of genius."); var findIt = smarties.match(/genius/gi); //Gobal and ignore case if(findIt) { document.write("The match is made!") }
Replaces the contents of a regular expression with a new string. (Use Perl regular expression format.)
Example:
var smarties =new String("A generation of genius."); var replaceIt = smarties.replace(/genius/,"science") document.write(replaceIt) //Returns 'A generation of science.'
Searches for a regular expression and returns the starting point.
Example:
var smarties =new String("A generation of genius."); var searchIt = smarties.search(/rat/) document.write("Mr. Rat begins at position " + searchIt +".")
Creates a substring beginning at position b and ending at e.
Example:
var pet = new String("Greater Swiss Mountain Dog") var alpine=pet.slice(14,22); document.write(alpine)
Creates a font in the format of <small> tag in HTML.
Example:
var littleGuy=new String("Chihuahua"); document.write(littleGuy.small( ));
Creates an array of strings from a single string, using a delimiter (d) to break the string into elements.
Example:
var farmersMarket=new String("strawberries-cantelope-oranges-apples") var order=farmersMarket.split("-"); document.write(order[3]);
Creates strikethrough characters. Based on the <strike> tag in HTML.
Example:
var alpha=new String("Trash"); document.write(alpha.strike( ));
Creates a subscript font. Based on the <sub> tag in HTML.
Example:
var alpha=new String("Australia"); document.write("That country is down under " + alpha.sub( ));
A substring of a string beginning at b and a length of l.
(This is a subtle but important difference from string.substring( ).)
Example:
var alpha=new String("JavaScript is too cool."); var work=alpha.substr(4,6) +"ing can be hard work." document.write(work);
A substring of a string beginning at b and ending at e.
Example:
var alpha=new String("JavaScript is too cool."); var work=alpha.substring(4,9) +"ing can be hard work." document.write(work);
Creates a superscript font position. Based on the <sup> tag in HTML.
Example:
var alpha=new String("Arctic Circle"); document.write("That place is way up there " + alpha.sup( ));
Forces all characters in a string to lowercase.
Example:
var alpha=new String("ALL UPPER CASE"); document.write(alpha.toLowerCase( ));
Forces all characters in a string to lowercase.
Example:
var alpha=new String("all lower case"); document.write(alpha.toUpperCase());
Changes characters from escape format to decoded format.
Example:
var alpha=new String("Testing%20one"); document.write(unescape(alpha));
Reference to window object.
Example:
window
Stops actions initiated by setInterval( ).
Example:
window.clearInterval.
Cancels setTimeout( ).
Example:
if (var clocker==4) { window.clearTimeout( ) }
Closes a specified window or the current window. (See window.open( ).)
Example:
window.close( ); ralph.close( );//ralph is variable name defined in opening.
Tests whether a specified window has been closed.
Example:
var checkWin=smWin.closed; //smWin is a var name defined //when window was opened if(checkWin) {....
Presents a question to ask the user. A cancel returns false.
Example:
function checkFirst( ) { if(window.confirm("You really want to close it?")) {; window.close( ); } }
A read/write string property used to display a message in the window status line.
Example:
var message="Look down here!"; window.defaultStatus=message; //The string "Look down here!" appears in status line.
Reference to the current document. (The window term is usually superfluous.)
Example:
var alpha=window.document.forms[2].elements[7].value;
Provides keyboard focus to a specified window or frame.
Example:
windows.frames[2].focus( )
Reference to frames within a window.
Example:
var numFrames=window.frames.length;
Returns the number of frames in a window.
Example:
var numFrames=window.length;
URL of the current HTML page loaded.
Example:
var where=window.location;
The number of pixels to move the window to the right and down. (NN requires UniversalBrowserWrite privilege to move off the screen.)
Example:
window.moveBy(40,50)
Moves a window to absolute x,y position. (NN requires UniversalBrowserWrite privilege to move off the screen.)
Example:
window.moveTo(250,400)
Name of the window specified in the window.open( ) statement.
Example:
var louise=window.open("","flowers") //"flowers" is the window's name, but to close the window use, //louise.close( )
Opens a new window for an existing page or new page. May use variable definition to open a window by naming arguments (url, name, features, and replace). Both major browsers accept the following features:
height location menubar resizable scrollbars status toolbar width
All arguments are separated by commas, and features are in parentheses and separated by spaces.
Example:
var winName=window.open(" ","services","height=200 width=300",true)
A frame's parent. Usually used in a frame page's script to reference another frame.
Example:
parent.side.document.location="http://www.sandlight.com" //'side' is a frame name in the same parent window.
A prompt window appears with question q and optional default d. User feedback can go into a variable.
Example:
function promptMe( ) { var alpha=window.prompt("How old are you",18); document.forms[0].elements[1].value=alpha; }//The variable alpha contains whatever the user typed in.
Resizes the window by rh height in pixels and rw width. Function adds pixels to current size. (NN requires UniversalBrowserWrite privilege to set either ah or aw to less than 100 pixels.)
Example:
window.resizeBy(200,100)
Resizes the window to the absolute height and width specified. (NN requires UniversalBrowserWrite privilege to set either ah or aw to less than 100 pixels.)
Example:
window.resizeTo(580,400)
Scrolls page to x,y coordinates on screen.
Example:
scrollTo(300,200);
Used mainly to clarify a window reference to itself.
Example:
window.self
Executes a script at an interval set in milliseconds. Both NN and IE use this form. IE does not use the second form, window.setInterval(function,milliseconds, arguments).
Example:
window.setInterval(alpha += 3, 5000);
Delays execution (f) for the specified number of milliseconds (d).
Example:
function ready( ) { window.setTimeout("document.reactR.src=react4.src",500); window.setTimeout("document.reactR.src=react1.src",1000); }
A read/write string property used to read or add transient message to the status line.
Example:
var temp = "Your frame now is Pictures." window.status = temp;
Usually used with frames to reference the top-level window in the frame.
Example:
var topDog=window.top;
CONTENTS |