×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

Js Window Object


For representing window in browser the window object is important one. It is the object of browser and automatically it is been created by the browser

We are having some methods of window object which we are enlisting below with the example:-.


Alert example

Mainly it is the popup message type which are having message and ok button

Let's take an example:-

<html>

<body>

<script>

    function msg(){

       alert("hello parveen");

}

</script>

<button type="button" onclick="msg()"> Click Here </button>

</body>

</html>

Output



Confirm example

It is just like the alert box but this dialog box include ok and cancel buttons too.

Let's take an example:-

<html>

<body>

<script>

    function text1(){

      var v=confirm("are you sure?");

   if(v==true){

   alert("ok");

}

   else{

   alert("cancel");

}

}

</script>

<button type="button" onclick="text1()"> Click Here </button>

</body>

</html>

Output



Prompt example

It is also like the alert box and confirm box but this dialog box mostly includes the imput from the user.

Let's take an example:-

<html>

<body>

<script>

    function text(){

      var v=prompt("what is your name?")



   alert("i am" +v);

}

</script>

<button type="button" onclick="text()"> Click Here </button>

</body>

</html>

Output



Some Boolean properties and methods are described below :-

Methods/Property 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.






JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute