What is a window object in Javascript ?
Window object is the object of the browser and not a javascript object.
Window object represents the window in the browser.
Window object is created automatically by the browser.
How to access the window object ?
Window objects can be executed with or without the ‘window’ prefix.
Syntax :
window.screen
or
screen
Javascript complete tutorial !!!
Click to Learn More about – Javascript online learning
What are the methods of window object ?
There are few methods of window object are as follows:
1. alert()
alert() method displays the alert box containing a message with ok button.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
alert("HI Good Morning, Have a nice day");
</script>
</head>
<body></body>
</html>
Output :

2. confirm()
confirm() method displays the confirm dialog box containing message with ok and cancel button.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
confirm("Do you wish to continue ?");
</script>
</head>
<body></body>
</html>
Output :

3. prompt()
prompt() method displays a dialog box to get input from the user.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
prompt("Do you wish to continue ?");
</script>
</head>
<body></body>
</html>
Output :

4. open()
open() method opens the new window.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
open("https://google.com");
</script>
</head>
<body></body>
</html>
Output :
A new window with (https://google.com) is loaded.
5. close()
close() method closes the current window.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
close();
</script>
</head>
<body></body>
</html>
Output :
This closes the current window.
6. setTimeout()
setTimeout() method performs action after specified time like calling function, evaluating expressions etc.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
setTimeout(
function(){
alert("Hi, Welcome after 2 seconds")
},2000);
</script>
</head>
<body></body>
</html>
Output :
