SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Bay area, CA
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using Javascript to obtain browser window size?

    Hi,

    Any know how I can use Javascript to obtain the window size of the page that you are in? I'm a novice Javascript programmer. I was looking thru some reference material and couldn't find anything.

    Thank you,
    George

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function zxcWinWHS(){
     if (
    document.all){
      
    zxcWS=document.body.scrollTop;
      if (
    navigator.userAgent.toLowerCase().indexOf("msie 6.0")!=-1&&navigator.userAgent.toLowerCase().indexOf("opera")==-1){
       
    zxcWW=document.documentElement.clientWidth;
       
    zxcWH=document.documentElement.clientHeight;
      }
      if (!
    zxcWW){
       
    zxcWW=document.body.clientWidth;
       
    zxcWH=document.body.clientHeight;
      }
     }
     else if (
    document.getElementById&&!document.all){
      
    zxcWS=window.pageYOffset;
      
    zxcWW=window.innerWidth;
      
    zxcWH=window.innerHeight;
     }
     return 
    zxcWW+'*'+zxcWH+'*'+zxcWS;

    this function works for IE6 strict and transitional and all other browsers I have tried

    It returns a string of the Width Height and Scroll Top

    extract Width=zxcWinWHS().split('*')[0];
    extract Height=zxcWinWHS().split('*')[1];
    extract ScrollY=zxcWinWHS().split('*')[2];


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •