java script objects
TRANSCRIPT
-
7/27/2019 Java Script Objects
1/23
-
7/27/2019 Java Script Objects
2/23
}
window.prompt("msg","default");
Displays a dialog box prompting the user for input
function disp_prompt(){
var name=prompt("Please enter your name","")if (name!=null && name!=""){
document.write("Hello " + name + "! How are you today?")}}
window.confirm("msg");
Displays a dialog box with a message, a Cancel, and an OK button
function disp_confirm(){var name=confirm("Press a button")if (name==true){document.write("You pressed the OK button!")
}else{document.write("You pressed the Cancel button!")
}
}
-
7/27/2019 Java Script Objects
3/23
window.open("URL", "name", "specs");
Opens a new browser window.
function open_win()
{window.open("http://www.fsu.edu","new_window","toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,width=400,height=400")}
-
7/27/2019 Java Script Objects
4/23
CGS 3066: JavaScript Objects: String Object
The String object is used to work with text.
Properties
Syntax: object.property_name
Grayed properties are of lessor importance.
Property Description
constructor
length Returns the number of characters in a string
Methods
Syntax: object.method_name()Grayed methods are of lessor importance.
Method Description
anchor("anchorname") Returns a string as an anchor
big() Returns a string in big text
blink() Returns a string blinking
bold() Returns a string in bold
charAt(index) Returns the character at a specified position
charCodeAt(i) Returns the Unicode of the character at a specified position
concat(string) Returns two concatenated strings
fixed() Returns a string as teletype
fontcolor() Returns a string in a specified color
fontsize() Returns a string in a specified size
fromCharCode() Returns the character value of a Unicode
indexOf(substring, index) Returns the position of the first occurrence of a specified string insideanother string. Returns -1 if it never occurs
italics() Returns a string in italiclastIndexOf(substring,index)
Returns the position of the first occurrence of a specified string insideanother string. Returns -1 if it never occurs. Note: This method starts
from the right and moves left!
link() Returns a string as a hyperlink
match(strMatch) Similar to indexOf and lastIndexOf, but this method returns thespecified string, or "null", instead of a numeric value
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.php -
7/27/2019 Java Script Objects
5/23
replace(strFind,strReplace)
Replaces the first instance of some specified characters with somenew specified characters
search(substring) Returns an integer if the string contains some specified characters, if
not it returns -1
slice(start, end) Returns a string containing the portion of the string from indexstartthrough index end. Ifendis not specified, it returns fromstartthrough
the end of the string.
small() Returns a string as small text
split(delimiter) Splits a string into an array of strings .Delimiteracts as the character
on which the string is divided.
strike() Returns a string strikethrough
sub() Returns a string as subscript
substr(start, length) Returns the specified characters. 14,7 returns 7 characters, from the
14th character
substring(start, end) Returns the specified characters. 7,14 returns all characters from the
7th up to but not including the 14th
sup() Returns a string as superscript
toLowerCase() Converts a string to lower case
toUpperCase() Converts a string to upper case
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsStringExample.php -
7/27/2019 Java Script Objects
6/23
CGS 3066: JavaScript Objects: Document Object
The Document object is used to access all elements in a page. The Document object's collections,properties, methods, and events are described below:
Collections
Collection Description
anchors[] Returns a reference to all Anchor objects in the document
applets[] Returns a reference to all Applet objects in the document
attributes[]
childNodes[]
embeds[] Returns a reference to all embedded objects in the document
forms[] Returns a reference to all Form objects in the document
images[] Returns a reference to all Image objects in the document
links[] Returns a reference to all Link objects in the document
plugins[]
styleSheets[] Returns a reference to all Stylesheet objects in the document
Properties
Syntax: document.property_name
Grayed properties are of lessor importance.
Property Description
alinkColor Sets or returns the color of the active links in the document
bgColor Sets or returns the background-color of the document
body Specifies the beginning and end of the document body
cookie Sets or returns all cookies associated with the document
documentElement Returns a reference to the root node of the document
domain Returns the document server's domain name
fgColor Sets or returns the text-color of the document
lastModified Returns the date and time the document was last modified
linkColor Sets or returns the color of the links in the document
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.php -
7/27/2019 Java Script Objects
7/23
referrer Returns the URL of the document that loaded the currentdocument
title Returns the title of the document (text inside the HTML title
element)
URL Returns the URL of the current documentvlinkColor Sets or returns the color of the visited links in the document
Methods
Syntax: document.method_name()
Grayed methods are of lessor importance.
Method Description
clear() Clears all elements in the document
close() Closes the output stream and displays the sent data
createAttribute("name") Creates an attribute with a specified name
createElement("tag") Creates an element
createTextNode("txt") Creates a text string
focus() Gives the document focus
getElementById("id") Returns a reference to the first object with the specified ID
getElementsByName("name") Returns a collection of objects with the specified NAME
getElementsByTagName("tag") Returns a collection of objects with the specified TAGNAME
open("mimetype"[,replace]) Opens a document for writing. If a document exists in thetarget it will be cleared. If this method has no arguments, a
new window with about:blank is displayed
write("str") Writes a text string to a document opened by open()
writeln("str") Writes a text string followed by a new line character to a
document opened by open()
Events
Syntax: document.event_name="someJavaScriptCode"
Grayed events are of lessor importance.
Event Description
onClick Executes some code when a Click event occurs
onDblClick Executes some code when a Doubleclick event occurs
onFocus Executes some code when a Focus event occurs
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsDocumentExample.php -
7/27/2019 Java Script Objects
8/23
onKeyDown Executes some code when a Keydown event occurs
onKeyPress Executes some code when a Keypress event occurs
onKeyUp Executes some code when a Keyup event occurs
onMouseDown Executes some code when a Mousedown event occurs
onMouseMove Executes some code when a Mousemove event occurs
onMouseOut Executes some code when a Mouseout event occurs
onMouseOver Executes some code when a Mouseover event occurs
onMouseUp Executes some code when a Mouseup event occurs
onResize Executes some code when a Resize event occurs
CGS 3066: JavaScript Objects: Form Object
The Form object is used to access all forms in a page. The Form object's collections, properties,
methods, and events are described below:
Objects
Syntax: objForm.object
Grayed objects are of lessor importance.
Object Description
button An GUI pushbutton control.
Methods are click(), blur(), and focus().
Properties:
name - The name of the button
type - The object's type. In this case, "button".value - The string displayed on the button.
checkbox An GUI check box control.
Methods are click(), blur(), and focus().
Properties:
checked - Indicates whether the checkbox is checked. This is aread or write value.defaultChecked - Indicates whether the checkbox is checked
by default. This is a read only value.
name - The name of the checkbox.type - Type is "checkbox".
value - A read or write string that specifies the value returned
when the checkbox is selected.
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.php -
7/27/2019 Java Script Objects
9/23
FileUpload This is created with the INPUT type="file". This is the same asthe text element with the addition of a directory browser.
Methods are blur(), and focus().
Properties:name - The name of the FileUpload object.type - Type is "file".
value - The string entered which is returned when the form is
submitted
hidden An object that represents a hidden form field and is used for
client/server communications.
No methods exist for this object.
Properties:
name - The name of the Hidden object.type - Type is "hidden".value - A read or write string that is sent to the server when the
form is submitted.
password A text field used to send sensitive data to the server.
Methods are blur(), focus(), and select().
Properties:
defaultValue - The default value.
name - The name of the password object."type - Type is "password".
value - A read or write string that is sent to the server when the
form is submitted.
radio A GUI radio button control.
Methods are click(), blur(), and focus().
Properties:
checked - Indicates whether the radio button is checked. This
is a read or write value.
defaultChecked - Indicates whether the radio button is checkedby default. This is a read only value.
length - The number of radio buttons in a group.
name - The name of the radio button.type - Type is "radio".
value - A read or write string that specifies the value returned
when the radio button is selected.
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.php -
7/27/2019 Java Script Objects
10/23
reset Properties:name - The name of the reset object.
type - Type is "reset".
value - The text that appears on the button. By default it is"reset".
select A GUI selection list. This is basically a drop down list.
Methods are blur(), and focus().
Properties:
length - The number of elements contained in the options
array.name - The name of the selection list.
options - An array each of which identifies an options that may
be selected in the list.selectedIndex - Specifies the current selected option within the
select listtype - Type is "select".
submit A submit button object.
Methods are click(), blur(), and focus().
Properties:
name - The name of the submit button.type - Type is "submit".
value - The text that will appear on the button.
text A GUI text field object.
Methods are blur(), focus(), and select().
Properties:defaultValue - The text default value of the text field.
name - The name of the text field.
type - Type is "text".
value - The text that is entered and appears in the text field. Itis sent to the server when the form is submitted.
textarea A GUI text area field object.
Methods are blur(), focus(), and select().
Properties:
defaultValue - The text default value of the text area field.
name - The name of the text area.type - Type is textarea.
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.php -
7/27/2019 Java Script Objects
11/23
value- The text that is entered and appears in the text areafield. It is sent to the server when the form is submitted.
Properties
Syntax: objForm.property_name
Grayed properties are of lessor importance.
Property Description
action This specifies the URL and CGI script file name the form is to
be submitted to. It allows reading or changing the ACTION
attribute of the HTML FORM tag.
elements An array of fields and elements in the form.
encoding This is a read or write string. It specifies the encoding method
the form data is encoded in before being submitted to theserver. It corresponds to the ENCTYPE attribute of the FORM
tag. The default is "application/x-www-form-urlencoded".
Other encoding includes text/plain or multipart/form-data.
length The number of fields in the elements array. I.E. the length of
the elements array.
method This is a read or write string. It has the value "GET" or
"POST".
name The form name. Corresponds to the FORM Name attribute.
target The name of the frame or window the form submission
response is sent to by the server. Corresponds to the FORMTARGET attribute.
Methods
Syntax: objForm.method_name()
Grayed methods are of lessor importance.
Method Description
reset() Used to reset the form elements to their default values.
submit() Submits the form as though the submit button were pressed by
the user.
Events
Syntax: objForm.event_name="someJavaScriptCode"Grayed events are of lessor importance.
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture07/domForm.php#elementshttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture07/domForm.php#elementshttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.php -
7/27/2019 Java Script Objects
12/23
Event Description
onreset Executes some code when a Reset event occurs
onsubmit Executes some code when a Submit event occurs
CGS 3066: JavaScript Form Validation
Philosophy
JavaScript is commonly used to validate information inputted into forms thereby ensuring that
information has been entered into required fields and, also, to ensure that the information is
plausible (i.e., that an e-mail address includes an "@" symbol or that a phone number does notcontain alpha characters [a-z or A-Z]). Note that form validation can be quite tricky. When
writing your validation code, put yourself in the user's shoes. Consider what information might
they, legitimately, want to input. A great frustration for any user is toseeminglyinput validinformation into a form and subsequently be told that it is not valid.
Consider a form that collects personal information such as your zip code, such as in the form
below.
First Name:
State:
Zip Code:
Country:
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.php#onsubmithttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsFormExample.php#onsubmit -
7/27/2019 Java Script Objects
13/23
A logical first step may be to make the zip code field required and a second step may be
to require that only numbers are accepted.
However, doing so would be be overly restrictive. Although U.S. postal codes are
composedprimarily of numbers, a person may choose to enter their fully-defined 9 digit
zip code, which would then contain a hyphen, such as 32308-1409.
To accommodate this, you may revise your validation code so that it allows only numbers
and the hyphen.
However, again, this is likely to be overly restrictive as international postal codes often
contain letters.
To accommodate, you modify your code so that if the country field is U.S. then only
numbers and hyphens are accepted but if the country is not the U.S., then numbers,
letters, and hyphens are accepted.
Is this sufficient to ensure that a properly-formed zip code is entered?
No, it is not. For example, "125" would be accepted by the validation code that is
outlined above.
To accommodate, you may revise the validation code so the U.S. postal codes must be 5
digits, followed by an optional hyphen, and then followed by 4 digits (these 4 digits
appear only if a hyphen has been entered). Under these guidelines, 32308-1409 and
32308 would be accepted, but 32-308 and 323081409 would not.
However, the story is still not over. For example, not all 5 digit numbers are valid postal
codes andif you collect the user's statethe zip code should correspond to a zip code
within the given state.
If the validation code were modified to account for these conditions, would the code be
fail-proof? Likely not. It is very difficult to address all situations that may arise and thatshould not be your goal. Your goal should be to incorporate validation code that accounts
for common situations. In general, validation code which is so restrictive that it ensures,
beyond all doubt, that the information entered by the user is of a given format will domore harm than as it may frustrate users.
Validation Techniques
View, as a text file, acollection of functions that may be used for validation purposes.
View sample forms and their validation code.
Form 1
Form 2
Form 3
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/jsFormValidation.txthttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/jsFormValidation.txthttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/formSample01.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/formSample02.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/formSample03.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/jsFormValidation.txthttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/formSample01.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/formSample02.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/formSample03.php -
7/27/2019 Java Script Objects
14/23
Typically, the information within a form is validatedby a functionthat is called when the
form is submitted.
Username:
Username:Submit
Note that the form tag, above, has an attribute that we have not yet seen - the onsubmitattribute.
"onsubmit" is an example of an event handler; event handlers will be discussed in greater detailwithin the DHTML lectures. In brief, an event handler is used to react to an event caused by the
user (i.e., when the user submits a form, clicks on a link, loads a page).
onsubmit="return validate(this);"
Looking at the onsubmit event handler one piece at a time:
onsubmitthe event handler itself, which returns the value of the validate function to the
browser. The validate function returns a boolean value. If the function, and therefore theevent handler, returns true then the form is passed to its action page. However, iffalse is
returned, then the browser will cancel the passing of the form to the action page.
returnthe return keyword acts as you might suspect - it returns a value. The values it
can return can be of any data type, and can be defined by custom statements or by core
objects. The return keyword is most often used within functions and within event
handlers. If the return keyword is used in a function body, a value is returned (or sent)
back to where function is called. If the return keyword is used in an event handler, avalue is returned (or sent) to the browser.
validate(this)a call to the validate function, which passes this as an argument
thisJavaScript provides a special keyword, "this", which is a reference to the object that
contains a JavaScript statement or function call. In this case, the keyword "this" passes a
reference to the form to the function "validate". In other words, the information containedin the form is made available to the function.
-
7/27/2019 Java Script Objects
15/23
"\n_____________________________" +"\nPlease re-enter and submit again!";window.alert(missinginfo);return false;
}else
return true;}
//-->
CGS 3066: JavaScript Form Validation (continued)
The discussion thus far has been to validate an entire form once it has been submitted. In many
cases, the form needs to be validated - or at least adjusted - as the user inputs the information.Examples:
when the user clicks inside the Name input box, which gives it focus, the phrase "Enter
name here" is deleted automatically. This saves the user from having to do so.
when the user selects more than 2 checkboxes, the user is alerted that they may not do so.
when the user indicates that, Yes, they have special dietary needs, the Dietary Needs
textarea is automatically given focus to encourage the user to elaborate.
when the user indicates that, No, they do not have special dietary needs, any text within
the Dietary Needs textarea is deleted.
when the inputs information into the Dietary Needs textarea, the Yes radio button is
automatically checked.
Note: much of this code relies on use of the keyword 'this'. In particular, it relies on 'this.form';
'this.form' refers to the parent form of the current element. I.e., specifying
-
7/27/2019 Java Script Objects
16/23
passes the contents on the entire form in which the input box is contained.
Name:Enter name here
1. For what platform would you like more information? Choose no more than 2.
Windows NT
Windows 2000
Windows XP
Linux
Unix
2. Do you have special dietary needs?
Yes | No
Dietary needs:
Submit Form
Reset Form
-
7/27/2019 Java Script Objects
17/23
//-->
Name:
For what platform would you like more information?
Choose no more than 2.
Windows NTWindows 2000
Windows XP
Linux
Unix
Do you have special dietary needs?
Yes |No
Dietary needs:
-
7/27/2019 Java Script Objects
18/23
GS 3066: JavaScript Objects: Window Object
The Window object corresponds to the browser window. A Window object is created
automatically with every instance of a or tag. A selection of the Window
object's collections, objects, properties, methods, and events are described below. Syntax to refer
to a window.
Collections
Collection Description
frames[] Returns all named frames in the window
Objects
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowReferring.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowReferring.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowReferring.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowReferring.php -
7/27/2019 Java Script Objects
19/23
Object Description
document Represents the HTML document object in the window.
event Represents the state of an event
history Contains the URLs visited from the window.
location Contains the current URL of the window.
navigator Contains information about the browser.
screen Contains information about the client's screen.
Properties
Syntax: window.property_name
Property Description
closed Returns a Boolean value that specifies whether the referencedwindow has been closed
defaultStatus Sets or returns the default text in the statusbar of the windows(will be displayed when the page loads)
dialogHeight Sets or returns the height of the modal dialog window
dialogLeft Sets or returns the left coordinates of the modal dialog window
dialogTop Sets or returns the top coordinates of the modal dialog window
dialogWidth Sets or returns the width of the modal dialog window
length Sets or returns the number of frames in the window
name Sets or returns the name of the window
opener Sets or returns a reference to the window that created the
window
parent Returns the parent window
returnValue Sets or returns the value returned from the modal dialog window
screenLeft Returns the x-coordinate of the upper left corner of the browser -
relative to the upper left corner of the screen
screenTop Returns the y-coordinate of the top corner of the browser -
relative to the top corner of the screen
self Returns a reference to the current window
status Sets or returns the text in the status bar of the window
top Returns the topmost ancestor window
Methods
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.php -
7/27/2019 Java Script Objects
20/23
Syntax: window.method_name()
Method Description
alert("msg") Displays an alert box with a message and an OK button
blur() Removes focus from the current windowclearInterval(ID) Cancels a timeout that is set with the setInterval() method
clearTimeout(ID) Cancels a timeout that is set with the setTimeout() method
close() Closes the current window
confirm("msg") Displays a dialog box with a message, a Cancel, and an OKbutton
focus() Sets focus on the current window
moveBy(x,y) Moves the window a specified number of pixels in relation to its
current co-ordinates
moveTo(x,y) Moves the window's left and top edge to the specified co-ordinates
open(["URL", "name", "specs",replace])
Opens a new browser window. The arguments can take thefollowing values:
"URL" - Optional. Specifies the URL of the page to display if no
URL is specified, a new window with about:blank is displayed)
"name" - Optional. Specifies the value for the target attribute ona form or a link. The following values are supported:
_blank URL is loaded into a new window
_media URL is loaded into the content area of the Media Bar
(IE6+)
_parent URL is loaded into the parent frame
_search URL is opened in the browser's search pane (IE5+)
_self URL replaces the current page
_top URL replaces any framesets that may be loaded
"specs" - Optional. A comma-separated list of items. Thefollowing values are supported:
channelmode =yes | no | 1 | 0
whether to display the window in theatermode. Default is no
directories = yes |no | 1 | 0
whether to add directory buttons. Default isyes
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.php -
7/27/2019 Java Script Objects
21/23
fullscreen = yes |
no | 1 | 0
whether to display the browser in full-screen
mode. Default is no. A window in full-screen
mode must also be in theater mode
height = number the height of the window, in pixels. Min.
value is 100left = number the left position, in pixels
location = yes |no | 1 | 0
whether to display the address field. Defaultis yes
menubar = yes |no | 1 | 0
whether to display the menu bar. Default isyes
resizable = yes |
no | 1 | 0
whether the window is resizable. Default is
yes
scrollbars = yes |no | 1 | 0
whether to display scroll bars. Default is yes
status = yes | no |
1 | 0
whether to add a status bar. Default is yes
titlebar = yes | no
| 1 | 0
whether to display the title bar. Ignored
unless the calling application is an HTML
Application or a trusted dialog box. Default isyes
toolbar = yes | no
| 1 | 0
whether to display the browser toolbar.
Default is yes
top = number the top position, in pixels
width = number the width of the window, in pixels. Min.value is 100
width = number the width of the window, in pixels. Min.value is 100
replace - Optional. Specifies whether the URL creates a newentry or replaces the current entry in the history list. The
following values are supported:
true URL replaces the current document in the history list
false URL creates a new entry in the history list
print() Prints the contents of the current window
prompt(["msg", "default"]) Displays a dialog box prompting the user for input. The
arguments can take the following values:
msg Optional. The message to display in the dialog box.
http://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.phphttp://ww2.cs.fsu.edu/~searles/cgs3066/lectures/lecture06/objectsWindowExample.php -
7/27/2019 Java Script Objects
22/23
Default is ""
default Optional. The default text in the input field
resizeBy(x,y) Resizes the window by the specified pixels. Note: This methoddoes not work on dialog windows
resizeTo(width, height) Resizes the window to the specified width and height. Note:This method does not work on dialog windows
scrollBy(x,y) Scrolls the content by the specified number of pixels. Note: Thevisible property of the window's scrollbar must be set to true if
using this method
scrollTo(x,y) Scrolls the content to the specified co-ordinates
setInterval(code, millisec[,
"lang"])
Calls a function / evaluate an expression every time a specified
interval (in milliseconds) has been reached. The arguments can
take the following values:
code Required. A pointer to a function or the code to beexecuted
millisec Required. The number of milliseconds
lang Optional. JScript | VBScript | JavaScript
setTimeout(code, millisec[,
"lang"])
Calls a function / evaluate an expression after a specified number
of milliseconds. The arguments can take the following values:
code Required. A pointer to a function or the code to beexecuted
millisec Required. The number of milliseconds
lang Optional. JScript | VBScript | JavaScript
* The default unit of measure for dialogHeight and dialogWidth in IE4 is em; in IE5 it is px.Other values to use: cm, mm, in, pt, pc, or ex. For consistent results, use px! Note: The min.
dialogHeight you can specify is 100px.
Events
Syntax: window.event_name="someJavaScriptCode"
Event Description
onBlur Executes some code when a Blur event occurs
onError Executes some code when an Error event occurs
onFocus Executes some code when a Focus event occurs
onLoad Executes some code when an Load event occurs
-
7/27/2019 Java Script Objects
23/23
onResize Executes some code when a Resize event occurs
onUnload Executes some code when an Unload event occurs