Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to write a browser-specific code using jQuery ?
Next article icon

How to get the size of screen, current web page and browser window using jQuery?

Last Updated : 23 Apr, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
jQuery can be used to get the dimensions of the current page. The dimensions include the screen, viewport and document height, and width.
  • Getting the window dimensions: Window size is the size of the browser window. This is the size that changes when the browser is resized. The windows height and width can be accessed with the height() and width() method after selecting the window object.
  • Getting the document dimensions: Document size is the size of the HTML document. The documents height and width can be accessed with the height() and width() method after selecting the document object.
  • Getting the screen dimensions: Screen size is the total size of the user's screen. The screen's height and width can be accessed with the height and width property.
Example: html
<!DOCTYPE html> <head>     <title>         Get the size of the screen, current         web page and browser window using         jQuery?     </title>          <script src=         "https://code.jquery.com/jquery-2.2.4.min.js">     </script> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>          <b>         How to get the size of the screen,          current web page and browser         window using jQuery?     </b>          <p>Window Height is:          <span class="windowHeight"></span>     </p>          <p>Windows Width is:          <span class="windowWidth"></span>     </p>          <p>Document Height is:          <span class="documentHeight"></span>     </p>          <p>Document Width is:          <span class="documentWidth"></span>     </p>          <p>Screen Height is:          <span class="screenHeight"></span>     </p>          <p>Screen Width is:          <span class="screenWidth"></span>     </p>          <button id="btn">         Click Here to check the dimensions         of the page:     </button>          <script type="text/javascript">         $("#btn").on("click", function () {             windowHeight = $(window).height();             windowWidth = $(window).width();             documentHeight = $(document).height();             documentWidth = $(document).width();             screenHeight = screen.height;             screenWidth = screen.width;              document.querySelector('.windowHeight').textContent                         = windowHeight;             document.querySelector('.windowWidth').textContent                         = windowWidth;             document.querySelector('.documentHeight').textContent                         = documentHeight;             document.querySelector('.documentWidth').textContent                         = documentWidth;             document.querySelector('.screenHeight').textContent                         = screenHeight;             document.querySelector('.screenWidth').textContent                         = screenWidth;         });     </script> </body>  </html>                     
Output:
  • Before clicking the button: before-click
  • After clicking the button: after-click

Next Article
How to write a browser-specific code using jQuery ?
author
sayantanm19
Improve
Article Tags :
  • Web Technologies
  • JQuery
  • jQuery-Misc

Similar Reads

  • How to make font-size that expands when we resize the window using jQuery ?
    In this article, we will learn how to increase or decrease the font-size of elements in HTML when the window is resized using jQuery. This can be used in situations where the font size has to be responsive according to the width of the browser window. Approach: We will be using the jQuery css(), wid
    2 min read
  • How to detect when the window size is resized using JavaScript ?
    Sometimes when we develop our site, we want to detect the size of the window, In this article, we are going to learn how to detect when the window size is resized using JavaScript The window resize event occurs whenever the size of the browser window gets changed. We can listen to the resize event i
    3 min read
  • How to print the content of current window using JavaScript ?
    The task is to print the content of the current window by using the window.print() method in the document. It is used to open the Print Dialog Box to print the current document. It does not have any parameter value. Syntax: window.print()Parameters: No parameters are required Returns: This function
    2 min read
  • How to trigger the window resize event in jQuery ?
    To discuss how to trigger the window resize event using jQuery. For this purpose, we will use the following library functions provided by jQuery. $(<element>).trigger(): This library function allows us to trigger both native and customized events. The method can be used independently or can be
    2 min read
  • How to write a browser-specific code using jQuery ?
    In this article, we will see how to write browser-specific code using jQuery. To write the browser-specific code, we will use the Navigator userAgent property and jQuery indexof() method. The Navigator userAgent property is used to get the user-agent header’s value sent to the server by the browser.
    2 min read
  • Cross-browser window resize event using JavaScript/jQuery
    The resize() method is an inbuilt method in jQuery that is used when the browser window changes its size. The resize() method triggers the resize event or attaches a function to run when a resize event occurs. jQuery has a built-in method for window resizing events. Syntax: $(selector).resize(functi
    2 min read
  • How to get font size of an element using jQuery ?
    In this article, we will see how to get the font size of an element using jQuery. To get the font size of an element, we will use css() method. The css() method is used to set or return the style property of the selected element. Syntax: var style = $(selector).css(property) Return value: This metho
    2 min read
  • How to check a webpage is loaded inside an iframe or into the browser window using JavaScript?
    An iFrame is a rectangular frame or region in the webpage to load or display another separate webpage or document inside it. So basically, an iFrame is used to display a webpage within a webpage. You can see more about iFrames here : HTML iFrames There may be a variety of reasons for checking whethe
    4 min read
  • How to get inner width (excluding the border) of an element using jQuery ?
    We can get the inner width of any element using the jQuery innerWidth() method. The innerWidth() method returns the inner width of the first matched element including padding but not border. Syntax: $(selector).innerWidth() So the inner width of an element is shown in the below image. The inner widt
    1 min read
  • How to calculate Width and Height of the Window using JavaScript ?
    In this article, we will know to calculate the width & the height of the window using Javascript. Given an HTML document that is running on a Window & we need to find the height and width of the window. The Window innerWidth property is used for returning the width of a window’s content area
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences