Javascript Window Object

Window Object

The window is the default object of the browser and is supported by all browsers. In simple words, the Window object represents the window of the 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 the 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 objects 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 a message along with an ok button.
confirm() To display the confirm dialog box containing a 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 follow and like us:
Content Protection by DMCA.com