Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I detect the user viewable area on the browser?

As you can see the image below, there is "A", "B", "C", "D" and "E" on the website, and the user may only can see the A, B, and a little parts of D in their browser. They need to require to scroll down the browser or some users may have a bigger screen, or a longer window on their browser that allow they can even see the element C.

Ok, my question is, is this possible to let me know what the user seeing on their browser using javascript? In this element, is "A", "B" and "D".

enter image description here

like image 865
DNB5brims Avatar asked Feb 14 '12 04:02

DNB5brims


People also ask

How can you detect the client's browser name?

You can use the navigator. appName and navigator. userAgent properties. The userAgent property is more reliable than appName because, for example, Firefox (and some other browsers) may return the string "Netscape" as the value of navigator.

What is browser viewport?

A viewport represents a polygonal (normally rectangular) area in computer graphics that is currently being viewed. In web browser terms, it refers to the part of the document you're viewing which is currently visible in its window (or the screen, if the document is being viewed in full screen mode).

What is browser detection in JavaScript?

JavaScript has a standard object called navigator that contains data about the browser being used. The navigator object has a lot of properties, but the . userAgent property — a string that contains data about the browser, operating system, and more– is all we'll need.

How can I tell if a div is in a viewport?

If the <div> element is in the viewport, its top and left are always greater than or equal zero. In addition, its distance from the right is less than or equal to the width of the viewport, and ids distance from the bottom is less than or equal to the height of the viewport.


1 Answers

Using the following, you can get the browser's viewport size.

window.innerHeight; window.innerWidth; 

http://bit.ly/zzzVUv - Had to use Google Cache as site would not load for me. Original page: http://www.javascripter.net/faq/browserw.htm

If you want to detect how far they have scrolled down the page, you can use

window.scrollX;   // Horizontal scrolling window.scrollY;   // Vertical scrolling 

Also, I have found a window object - window.screen. On my system it has the following data:

window.screen.availHeight = 994; window.screen.availLeft = 0; window.screen.availTop = 0; window.screen.availWidth = 1280; window.screen.colorDepth = 32; window.screen.height = 1280; window.screen.pixelDepth = 32; window.screen.width = 1280; 

I hope these answer your question sufficiently.

like image 155
Shane Avatar answered Sep 20 '22 18:09

Shane