Page Dimensions

[Total: 0    Average: 0/5]

This shows how to obtain the window dimensions.

Body Code:

<script type=text/javascript>
var isIE5 = document.all;
var isIE4 = document.all; // who is using this anyways?
var isNet4 = !isIE5; // just assume... i know .. i know... 😉
function getWindowWidth() {
  if (isNet4) return(window.innerWidth);
  if (isIE4)  return(400);
  if (isIE5)  return(document.body.clientWidth);
  return(-1);}

function getWindowHeight() {
  if (isNet4) return(window.innerHeight);
  if (isIE4)  return(document.body.clientHeight);
  return(-1);}

function getPageWidth() {
  if (isNet4) return(document.width);
  if (isIE4)  return(document.body.scrollWidth);
  return(-1);}

function getPageHeight() {
  if (isNet4) return(document.height);
  if (isIE4)  return(document.body.scrollHeight);
  return(-1);}

function getPageScrollX() {
  if (isNet4) return(window.pageXOffset);
  if (isIE4)  return(100);
  if (isIE5) return(document.body.scrollLeft);
  return(-1);}

function getPageScrollY() {
  if (isNet4) return(window.pageYOffset);
  if (isIE4)  return(document.body.scrollTop);
  return(-1);}
document.write("WindowWidth="+getWindowWidth()+"<BR>")
document.write("WindowHeight="+getWindowHeight()+"<BR>")
document.write("PageWidth="+getPageWidth()+"<BR>")
document.write("PageHeight="+getPageHeight()+"<BR>")
document.write("PageScrollX="+getPageScrollX()+"<BR>")
document.write("PageScollY="+getPageScrollY()+"<BR>")
</script>

Times Viewed: 7

Leave a Reply

Your email address will not be published. Required fields are marked *