You are on page 1of 4

Javascript Crash Course Notes

P A R T IFriday Evening 4 How to write Javascript Functions


SESSION
y y y y document.write( ); Two types of variables- Global and Local
<script language=javascript src=babyPalooza.js></script> -external source code file

functionfunc_name (paramx,paramy,etc..){} - defining function should have brackets even if it only has a line of code in it terms: o code block any group of codes enclosed in {} o function- is a code block with a name

P A R T IISaturday Morning 5 Working with JavaScript Strings


SESSION
y y y y y y y var cost = 199; cost += string.length
greeting.charAt( X)); - specifies a single character from the string (at position X) string.indexOf(query) ; - searches the string query from position 0; if not found, returns a value of -1.

; - converts a number into string

string.toUpperCase();string.toLowerCase();

lastIndexOf( query ); starts searching from the last element in the string string.substring(x,y); extracts string from position x to y; y is optional and if unspecified, it extracts from x to string.length

DANIEL O. MONTES| page 1

Javascript Crash Course Notes

6 Working with JavaScript Arrays


SESSION
y y y y y y y y y y y new Array() new Array( length) new Array( item1,item2.etc) concat()- join multiple arrays together into a single new Array object. join(), toString() - combine individual elements of an array into a single string. pop() - removes and returns the last statement in the aray object push() - puts new item at the end of the array reverse() -reverse the order of the elements of an Array object. shift() - remove the first element of an array (element 0) and move the other elements up one. slice() - return a new array object containing a subset of the elements in the original array; e.g. slice(0,2) //gets first TWO elements only sort(userDefinedFunction) -method will let you sort the contents of an Array object using whatever sorting process you want. You simply have to specify an appropriate sorting function when you call the sort() method. splice([int X-element number to be deleted], [int Y-elements to be deleted starting from element X]) splice(x,y,[items to replace from element x]) unShift() - adds an element to the beginning of the array and move all the old elements up one String.split( char -split determiner ) a string manipulation method

y y y y

7 Understanding the Browser Object Model


SESSION
y y y y y y Window object is the web browser window which encapsulates other objects Document object is the HTML document loaded in the web browser Frames array Location property a string containing the address of the web browser Navigator object the brand, version and capabilities of the web browser Recall <form> tag in HTML

DANIEL O. MONTES| page 2

Javascript Crash Course Notes

8 Working with the Window Object


SESSION
Properties of the window object y y y y y y y y window.closed = boolean; if window is open then close==false. window.defaultStatus =( string )-the string that will be displayed in the status bar window.document represents the document that has currently loaded to a browser window.frames=( frameid );This property is an array containing references to all the named child frames in the current window. window.history -This property's value is the window's History object, containing details of the URL's visited from within that window. See History object. window.location - contains details of the current URL of the window and its value is always the Location object for that window. window.name = string -This property is used to return or set a window's name. for (x in navigator) document.write( x + = + navigator[x] + <br /> ); -an array containing the property of the browser being opened. window.opener - document.opener.name- When opening a window using window.open, use this property from the destination window to return details of the source window. This has many uses, for example, window.opener.close() will close the source window. window.parent -This property is a reference to the window or frame that contains the calling child frame. window.status- temporary status message replaced by defaultStatus. window.top -This property is a reference (or synonym) for the topmost browser window.

y y y

Methods of the window object y y y y y y y y y alert(stringX) alert dialog box blur() -used to remove focus from the current window. varintervalID = setInterval( 'writeit()', 2000); close() - will close the associated browser window confirm( string ) - lets you ask the user a simple OK or Cancel question window.focus() -used to give focus to the specified window. This is useful for bringing windows to the top of any others on the screen. moveBy([(-)left,right],[(-)up,down]) moveTo(x,y) moves the window to an absolute position on the screen open() opens a browser ; can have the following parameters o url -This is the Web address of a Web page that you want toautomatically load into the new window. o Name - This is a string that will be placed into the window.nameproperty of the new window.

DANIEL O. MONTES| page 3

Javascript Crash Course Notes featuresList - This is a string specifying the features the new windowshould have. This parameter lets you specify how big thewindow should be, if it should have toolbars, scroll bars,and so on. o Replace - This is a Boolean value that specifies if the Web addressspecified in the first parameter should replace the currententry in the history list. var response = prompt( question , defaultresponsevalue ); resizeTo(height,width) scroll() and scrollTo() scrollBy(x,y) -scroll a document a specified number of pixels fromits current position varintervalID =setInterval( string ,millisecondsbeforeiteration) and clearInterval(intervalID) setTimeout( string ,timeinmilliseconds) and clearTimeout() o

y y y y y y

9 Working with the Document Object


SESSION
Properties of the Document Object y
y y

document.alinkColor = gray; color of the current active link document.bgColor = red; vartheCookie = document.cookie; // read the cookie document.cookie = theCookie; // write the cookie

DANIEL O. MONTES| page 4

You might also like