Overview of JavaScript Objects

By aathishankaran Viewed: 31762 times Emailed: 279 times Printed: 275 times Bookmark and Share



When you begin to look closely at the JavaScript object hierarchy you can see that each object falls into one of two categories: Navigator objects and built-in language objects. This section looks at these sets and introduces you to each of the objects within them. 

Navigator Objects 

Most of the functionality built into JavaScript centers around what you can do with HTML pages. The first set of objects Navigator objects generally has a correlation to the browser and HTML tags within it. 

Window Object 

A Web browser-whether it's Netscape Navigator, Microsoft Internet Explorer, or whatever- is presented to the user in a window. Everything a user does with the browser is performed within that window. Moreover, every screen element is also contained inside that window. The window object provides a direct corollary to this metaphor. It is considered the highest-level object of all objects in the JavaScript object hierarchy and contains all other Navigator objects (except for the Navigator object itself). Just as you can have multiple windows open in your browser, you can work with multiple window objects at once in your code. 

The window object has no HTML tag equivalent, although you do define its event handlers (onLoad, onUnload) in the <BODY> tag. Within JavaScript code, you work with a window object as shown in the following example. Suppose you wart to add text to the status bar of the window. The code follows: 

EXAMPLE for OnLoad and OnUnLoad

<head>

<html>

<script>

function ab (){

alert ("The alert is inside user defined javascript function");

}

</script>

</head>

<body onLoad="alert('WELCOME')" onUnload="alert('COME AGAIN')">

<a href=" javascript: ab () "

onMouseOver="

window.status='User defined function'"

onMouseOut="window.status="">click</a>

</body>

</html> 

Frame Object 

As you learn in this book, frames are especially important objects to use to enhance the presentation of your Web application. The frame object represents a frame within a frameset. In a multi-frame presentation, your window object is the page that contains the <FRAMESET>definition, whereas the other pages are considered frames in that context. 

Location Object 

The Web is all about content presentation. Every window object is designed to display content to the user, but that content must come from somewhere. The origin of the page is thus contained in the location object. The location object is used to store all URL information for a given window. Although users see URL information in the Location box on-screen, you can work with that same information with the location object. 

If you want to retrieve the protocol portion of the current URL and evaluate it, you use the following: 

function evalProtocol()

{

curProtocol= window.location.protocol

if (curProtocol == "http:")

{

alert("The document comes from the Web.")

}

else

{

if (curProtocol == "file:")

{

alert("This document comes from your hard drive.")

}

else

. {

alert("This document comes from somewhere else.")

}

}

}




Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:


Enter Code:
The Captcha image

Latest Tutorials

[2010-09-02]Steps in using verisign certificate with Glassfish appserver
[2010-08-02]emulator 0 terminated while waiting for it to register!
[2010-08-02]Cannot run program "C:\Program Files\Java\jre6\bin\javac.exe": CreateProcess error=2, The system cannot find the file specified
[2010-08-01]Step by Step guide to setup freetts for Java
[2010-07-31]Speech Packages available for Java API
[2010-07-31]Tutorial on setting up freetts with maven
[2010-07-31]package com.sun.speech.freetts does not exist.
[2010-07-31]Text to Speech conversion program in Java
[2010-07-31]How to create wav file using freetts
[2010-07-31]How to set the width of a Text element in JavaFX?
[2010-07-31]Major components of FxObjects in JavaFX
[2010-07-03]Using the AWS SDK for Java in Eclipse
[2010-07-03]Using the AWS SDK for Java
[2010-01-01]Converting properties using PropertyEditors and Other Spring features worth mentioning
[2010-01-01]How to create an array and method in JSP

More Latest News

Most Viewed Articles (in last 30 days)
How to use ArrayList in Java
XML and Java - Parsing XML using Java Tutorial
How to use Iterator in Java
How to Send SMS using Java Program (full code sample included)
Using StringTokenizer in Java
Using substring( ) in Java
FileReader and FileWriter example program in Java
indexOf( ) and lastIndexOf( ) in Java
HashMap example in Java
wait(), notify() and notifyAll() in Java - A tutorial
Abstract classes in Java
compareTo( ) in Java
Method Overriding in Java
instanceof sample program in Java
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Most Emailed Articles (in last 30 days)
Components of program
How to Send SMS using Java Program (full code sample included)
XML and Java - Parsing XML using Java Tutorial
Why java is important to the Internet
How to use ArrayList in Java
Execute system commands in a Java Program
FileReader and FileWriter example program in Java
Recursion in java
indexOf( ) and lastIndexOf( ) in Java
What is Java?
Method Overloading (function overloading) in Java
compareTo( ) in Java
Sample Java Script that displays a movable clock
History of Object
How to use Iterator in Java