PDA

View Full Version : Get available document size



buildrebuild
Sep 13th, 2007, 08:09 PM
Hi,

I have tried looking for a fool-proof script to detect a users inner browser window size but can't find one. What I need is to obtain the available space within a browser excluding tollbars etc, just where the website is shown, and deliver content appropriately.

Any help would be very much appreciated.

Thanks,
BR

Philip M
Sep 13th, 2007, 10:37 PM
I don't think that can be done. The user can change the size of the window at any time.

rwedge
Sep 13th, 2007, 11:20 PM
Here's an example using onresize
<style type="text/css">
html, body { overflow: auto; }
</style>

<script type="text/javascript">
function getWinSize() {
var winWidth = 0, winHeight = 0, d = document;
if (typeof (window.innerHeight) == 'number') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else {
if (d.documentElement && d.documentElement.clientHeight) {
winWidth = d.documentElement.clientWidth;
winHeight = d.documentElement.clientHeight;
} else {
if (d.body && d.body.clientHeight) {
winWidth = d.body.clientWidth;
winHeight = d.body.clientHeight;
}
}
}
document.getElementById('win').innerHTML = winWidth + ' x ' + winHeight;
}
window.onresize = getWinSize;
</script>

<div id="win"></div>

buildrebuild
Sep 14th, 2007, 01:08 PM
Thanks!
I will try that out.