This issue on Soen may be of interest. In particular, I compile here some of the suggestions given.
Get page and browser sizes with jQuery:
$(window).height(); // altura do browser
$(document).height(); // altura do documento HTML
$(window).width(); // comprimento do browser
$(document).width(); // comprimento do documento HTML
Get screen size:
screen.height;
screen.width;
Alternative without jQuery:
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
Another way to get screen dimensions, apparently supported by browsers in general:
alert(window.screen.availWidth);
alert(window.screen.availHeight);
I tested them on the browser console (Firefox 27.0.1), and they all work. It is a matter of seeing which is the measure that interests you most, possibly that of the browser window.
I do not know if it is possible to send this data together with the page request. However, you can choose to Lazy charging of the images, if possible. I would use some temporary element in HTML to fill in the space, and make it clear to the user that something is still missing. Then load the right images as quickly as possible. Example:
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function () {
if ((window.screen.availHeight < 1234) &&
(window.screen.availWidth < 1234))
document.getElementById("img1").src = "small";
else
document.getElementById("img1").src = "big";
})
</script>
</head>
<body>
<img id="img1" src=""/>
<p>Algum texto.</p>
</body>
</html>
Alternatively, you can take a look at the media queries of CSS3, help yourself. Here’s a article that talks a little about the subject.
I think when making the request to the server you have to send the device information, so the server will handle the information depending on the device.
– CesarMiguel
Yes... Indeed. But how to access this data? Specifically speaking, the screen dimensions?
– Pedro Vinícius
I think the @afsantos response is correct. I would go the same way :)
– CesarMiguel
Screen size is not a parameter sent naturally in the HTTP request, you can create an extension for the browser that enters these values, or put a cookie with this data.
– mau humor