The innerWidth property in JavaScript returns the width and innerHeight property returns the height of window content area.
Syntax:
window.innerWidth window.innerHeight
Parameter: It doesn’t required any parameters.
Return Value: It Returns a number, Representing the Width and Height of the window’s content area.
Note: For IE 8 i.e (Internet Edg 8) or earlier, use clientWidth and clientHeight to get width and height of window.
Example:
<!DOCTYPE html> <html> <head> <title>Browser Inner width and height</title> <style> body{ text-align:center; } .gfg { font-size:40px; font-weight:bold; color:green; } </style> </head> <body> <div class = "gfg" >GeeksforGeeks</div> <h2>Browser Window</h2> <p id= "demo" ></p> <script> var Width, Height, result; // height and width of Browser window Width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; Height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; // Display Width and Height. result = document.getElementById( "demo" ); result.innerHTML = "Browser inner width: " + Width + "<br>Browser inner height: " + Height; </script> </body> </html> |
Output:
leave a comment
1 Comments