Home / code / javascript

Window in Javascript

With the window object you can manipulate windows in JavaScript.

The window object has numerous useful methods, including the following:

  • open and close: Opens and closes a browser window; you can specify the size of the window, its content, and whether it has a button bar, location field and other "chrome" attributes.
  • alert: Displays a Alert dialog box with a message.
  • confirm: Display a confirm dialog box with OK and Cancel buttons.
  • prompt: Displays a prompt dialog box with a text field for entering a value.
  • blur and focus: Removes focus from, or gives focus to a window.
  • scrollTo: Scrolls a window to a specified coordinate.
  • setInterval: Evaluates an expression or calls a function each time the specified period elapses.
  • setTimeout: Evaluates an expression or calls a function once after the specified period elapses.

For a full list of the window object properties, methods and event handlers take a look here.

Example :

var inputedData = prompt ("Please type something.","");
if(confirm("Are you sure you typed "+inputedData+"?"))
{
  alert ("Ok, you did type "+inputedData+"!");
}
else
{
  alert ("No, you did not type "+inputedData+", did you?  OK.  Guess ya did.");
}

Location

window has also several properties you can set, such as location and status

You can set location to redirect the client to another URL.

location = "http://home.netscape.com"

Status bar

You can use 2 window properties, status and defaultStatus, to display messages in the browser status at the bottom of the window. Browsers normally uses the status bar to display such messages as "contacting host...". The defaultStatus messages appears when nothing else is in the status bar. The status property displays a transient messages in the status bar, such as when the user moves the mouse pointer over a link.

Example:

defaultStatus = "Some rise, some fall, some climb ... to get to Terrapin"

Another example:

<A HREF="contents.html"
  onMouseOver="window.status='Click to display contents'; return true">
Contents</a>

 

TOP

Latest script:

 

Books: