Browser Size
Version 1.00
written by Gerald Holdsworth

This is a simple demonstration of how to get the width and height of the visible area used by the browser. The two functions, <I>getViewWidth</I> and <I>getViewHeight</I> are used in other projects on this page.

These functions are simply cross-browser compatible functions of Javascript's <I>window.innerWidth</I> and <I>window.innerHeight</I>.

Click here for a demo

Javascript for 'Browser Size':
function getViewWidth()
{
 if (typeof window.innerWidth!='undefined')
  w=window.innerWidth;
 else if (typeof document.documentElement!='undefined' && typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0)
  w=document.documentElement.clientWidth;
 else w=document.getElementsByTagName('body')[0].clientWidth;
 return w;
}
function getViewHeight()
{
 if (typeof window.innerHeight!='undefined')
  w=window.innerHeight;
 else if (typeof document.documentElement!='undefined' && typeof document.documentElement.clientHeight!='undefined' && document.documentElement.clientHeight!=0)
  w=document.documentElement.clientHeight;
 else w=document.getElementsByTagName('body')[0].clientHeight;
 return w;
}
function updateDimensions()
{
 var browserWidth=getViewWidth();
 var browserHeight=getViewHeight();
 var el=document.getElementById('browserSize');
 el.innerHTML=browserWidth+' x '+browserHeight+'px';
}
Click here to download.

If you would like to email me, put gerald@ in front of the domain name, insead of www..
©2011-2020 Gerald Holdsworth IT Services