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.

Example1: Open and close new window

<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 Example1

Example2: Set status

<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 Example2

Example3: SetTimeout and SetInterval

<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 Example1

See Also

Javascript Built in String Object
Javascript Built in Number Object
Javascript Built in Math Object
Javascript Built in Date Object
Javascript Built in Arrays Object
Javascript Built in Boolean Object
Javascript Built in RegExp Object
Javascript Built in JSON Object


 
SHARE THIS IF YOU LIKE!
submit to reddit
SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.