javascript window object

Window Object

Window is the default object of the browser and is supported by all the browsers. In simple words, the Window object represents the window of browser. Window is not an object of javascript; but all the JavaScript objects, functions, and variables are a property of the window object. There are various other objects of javascript that are considered as a property of window. The document object, like all other javascript objects is also a property of the window object. There are various methods and properties of window object including;

 

Properties of Window Object:

PROPERTY USES
window.innerHeight To get the inner height of the browser window in pixels.
window.innerWidth To get the inner width of the browser window in pixels.

 

Methods of Window Object:

METHOD USES
window.moveTo() To move the current window.
window.resizeTo() To resize the current window.
alert() To display the alert box containing message along with an ok button.
confirm() To display the confirm dialog box containing message along with an ok and a cancel button.
prompt() To display a dialog box to get input from the user.
open() To open a new window.
close() To close the current window.
setTimeout() To perform an action after a specified time.

 

Example:

<!DOCTYPE html>
<html>
<body>
 
<script type="text/javascript">  
function msg(){  
alert("WELCOME to the WORLD of JAVASCRIPT!!");  
}  
</script>  
<input type="button" value="CLICK ME" onclick="msg()"/>  
 
</body>
</html>
Please Share