Home » Window Object

Window Object

The window object represents a window in browser. An object of window is created automatically by the browser.

Window is the object of browser, it is not the object of javascript. The javascript objects are string, array, date etc.

Note: if html document contains frame or iframe, browser creates additional window objects for each frame.

Methods of window object

The important methods of window object are as follows:

Method Description
alert() displays the alert box containing message with ok button.
confirm() displays the confirm dialog box containing message with ok and cancel button.
prompt() displays a dialog box to get input from the user.
open() opens the new window.
close() closes the current window.
setTimeout() performs action after specified time like calling function, evaluating expressions etc.

Example of alert() in javascript

It displays alert dialog box. It has message and ok button.


Output of the above example


Example of confirm() in javascript

It displays the confirm dialog box. It has message with ok and cancel buttons.


Output of the above example


Example of prompt() in javascript

It displays prompt dialog box for input. It has message and textfield.


Output of the above example


Example of open() in javascript

It displays the content in a new window.


Output of the above example


Example of setTimeout() in javascript

It performs its task after the given milliseconds.


Output of the above example

You may also like