Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the size of the browser window using Prototype.js?

Tags:

prototypejs

How do I get the size of the browser window using Prototype.js version 1.6.0.3?

like image 534
DaveC Avatar asked May 07 '09 09:05

DaveC


People also ask

How do I know the size of my browser window?

Use window. innerWidth and window. innerHeight to get the current screen size of a page.

How do I get the width of a window in HTML?

If you need to obtain the width of the window minus the scrollbar and borders, use the root <html> element's clientWidth property instead. The innerWidth property is available on any window or object that behaves like a window, such as a frame or tab.

How do you find the width and height of a viewport?

You can use the window. innerHeight property to get the viewport height, and the window. innerWidth to get its width. let viewportHeight = window.

What does Window innerWidth return?

Definition and Usage The innerWidth property returns the width of a window's content area.


2 Answers

According to the Prototype API documentation:

var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
var width = viewport.width; // Usable window width
var height = viewport.height; // Usable window height
like image 75
PatrikAkerstrand Avatar answered Oct 21 '22 12:10

PatrikAkerstrand


And the same idea but more compact:

var WindowSize = Class.create({
    width: window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth),
    height: window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight)
});
like image 31
Pedro Bezunartea López Avatar answered Oct 21 '22 14:10

Pedro Bezunartea López