Javascript Window Object

In Javascript BOM consists of the different objects such as navigator, history, screen, location and document which are children of window object. The BOM is not standardized and can change based on different browsers.

Window Object

The window object is the parent of all objects in the object hierarchy. Basically it defines a broeser window.

The methods included in the window object are:

  • Alert : Display an alert dialog box with specified message.
  • Confirm : Display an alert dialog box with specified message and "Ok" and "Cancel" button.
  • Close : Close a window.
  • Open : Open a window.
  • Prompt : Display an dialog box containing a text field and message.
  • Blur : Remove focus from a window.
  • Focus : Set focus to a window.
  • ScrollTo : Scroll a window to a specified co-ordinate.
  • SetInterval : Evaluates given expression after a set interval.
  • SetTimeout : Evaluates given expression after a specified time out.

Window object also has a few properties which can be set. These properties are:

  • Location : This will be load the page or redirect the page specified by location.
  • Status : This will be display the text or message on the status bar of the browser.

Javascript Open and Close New Window Example

<HTML>
<TITLE>Example of Window Object</TITLE>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
//Open new window
function aboutWindow()
{
window.open('JSStrikers_Bom/aboutUs.html','About',
"width=100px;height=100px;toolbar=no;menubar=no;scrollbar=no;");
}
</SCRIPT>
</HEAD>
<BODY>
<input type="button" value="Open new window demo+" 
onClick="aboutWindow();">
</BODY>
</HTML>
Javascript Window Object Example

Javascript Set status Example

<HTML>
<TITLE>Example of Window Object</TITLE>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
//Open new window
function openWindowSetStatus()
{
window.open('JSStrikers_Bom/statusMessage.html','Learning Window.status method',
"width=100px;height=100px;toolbar=no;menubar=no;scrollbar=no;");
}
</SCRIPT>
</HEAD>
<input type="button" value="Open new window demo" 
onClick="openWindowSetStatus();">
<BODY>
</BODY>
</HTML>
Javascript Window Object Example

Javascript SetTimeout and SetInterval Example

<HTML>
<TITLE>Example of Window Object</TITLE>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
//Open new window
var childWindow;
function openAboutUs()
{
	childWindow = window.open('JSStrikers_Bom/aboutUs.html',
	'Learning SetInterval method',
	"width=50px;height=50px;toolbar=no;menubar=no;scrollbar=no;");
	setTimeout('closeAboutUs()',3000);
}
function closeAboutUs()
{
	childWindow.close();
}
</SCRIPT>
</HEAD>
<input type="button" value="Set Interval" 
onClick="setInterval('openAboutUs()',1000);">
<BODY>
</BODY>
</HTML>
Javascript Window Object Example