- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the size of the screen, current web page and browser window in JavaScript
To get the current screen size of a web page, use the window.inner. We can also use the window.outerWidth and window.outerHeight as shown below to get the outer width and height of the web browser windows.
We will see two examples −
- Get the Inner Width and Height
- Get the Outer Width and Height
Get the Inner Width and Height
To get the current screen size of a web page, use the window.innerWidth and window.innerHeight −
var wd = window.innerWidth; var ht = window.innerHeight;
Example
Let us see an example −
<!DOCTYPE html> <html> <body> <h1>Current Browser Window Size</h1> <p>Following is the size of the current window:</p> <p id="test"></p> <script> var wd = window.innerWidth; var ht = window.innerHeight; var x = document.getElementById("test"); x.innerHTML = "Width = " + wd + ", Height = " + ht + "."; </script> </body> </html>
Output

Get the Outer Width and Height
Use the window.outerWidth and window.outerHeight as shown below to get the outer width and height of the web browser windows −
var wd = window.outerWidth; var ht = window.outerHeight;
Example
Let us see the example −
<!DOCTYPE html> <html> <body> <h1>Outer Width and Height</h1> <p>Following is the size:</p> <p id="test"></p> <script> var wd = window.outerWidth; var ht = window.outerHeight; var x = document.getElementById("test"); x.innerHTML = "Width = " + wd + ", Height = " + ht + "."; </script> </body> </html>
Output

- Related Articles
- How to get the protocol and page path of the current web page in JavaScript?
- How to set the size of the browser window in Selenium?
- Implement Onclick in JavaScript and allow web browser to go back to previous page?
- How to close a current tab in a browser window using JavaScript?
- JavaScript BOM Window Screen
- How to get the screen size in Tkinter?
- How to get the number of the internet host port for the current page in JavaScript?
- What is the maximum size of a web browser's cookies value?
- How to make the web page height to fit screen height with HTML?
- How to find the inner height and inner width of a browser window in JavaScript?
- How to get the Width and Height of the screen in JavaScript?
- Which is the event when the browser window is resized in JavaScript?
- Difference between Web Browser and Web Server.
- Get the Contents of a Web Page in a Shell Variable on Linux
- How can I get the current screen orientation in Android?

Advertisements