< Javascript Tutorial

Javascript window object

← Previous Next →


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.

<script type="text/javascript">

function msg(){  
 alert("Hello Alert Box");  
}  
</script>
  
<input type="button" value="click" onclick="msg()"/>

Example of confirm() in javascript

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

<script type="text/javascript"> 
function msg(){  
    var v= confirm("Are u sure?");  
    if(v==true){  
    alert("ok");  
    }  
    else{  
    alert("cancel");  
    }    
}  
</script>

<input type="button" value="delete record" onclick="msg()"/>
← Previous Next →