Get The Size Of The Screen, Current Web Page And Browser Window

To get the size of the screen, current web page, and browser window using JavaScript, you can use the window object and its properties. Here’s an example:

// Get the size of the screen
var screenWidth = window.screen.width;
var screenHeight = window.screen.height;

console.log('Screen width: ' + screenWidth);
console.log('Screen height: ' + screenHeight);

// Get the size of the current web page
var pageWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var pageHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

console.log('Page width: ' + pageWidth);
console.log('Page height: ' + pageHeight);

// Get the size of the browser window
var windowWidth = window.outerWidth;
var windowHeight = window.outerHeight;

console.log('Browser window width: ' + windowWidth);
console.log('Browser window height: ' + windowHeight);

In this example, window.screen.width and window.screen.height give you the size of the screen. The page width and height can be obtained using window.innerWidth or document.documentElement.clientWidth or document.body.clientWidth, and respectively for the page height. The browser window width and height can be retrieved using window.outerWidth and window.outerHeight.

About the Author Rex

I'm a passionate tech blogger with an insatiable love for programming! From my early days tinkering with code, I've delved into web dev, mobile apps, and AI. Sharing insights and tutorials with the world is my joy, connecting me to a global community of like-minded tech enthusiasts. Python holds a special place in my heart, but I embrace all challenges. Constantly learning, I attend tech conferences, contribute to open-source projects, and engage in code review sessions. My ultimate goal is to inspire the next generation of developers and contribute positively to the ever-evolving tech landscape. Let's code together!