×

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 text(){

        alert("i am alert box");

}

</script>

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

</body>

</html>

Output of this program



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 text(){

        confirm("i am confirm box");

}

</script>

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

</body>

</html>

Output of this program



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 textprompt(){

        var a = prompt("What is your name ?");

        document.getElementById('main').innerHTML = a;

}

</script>

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

<p id="main"> <p>

</body>

</html>

Output of this program



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