Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts

    return client height / width.

    i need the innerHeight and innerWidth of the clients browser window to be returned from a function.

    here is what i have however some times the value being returned is in fact greater than the browser window (only by a few pixles) i'm assuming this has something to do with 'tabs' in my browser.

    Code:
    function getW(){
    var w;
    if(document.innerWidth){ w=document.innerWidth;
    } else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
    } else if(document.body){ w=document.body.clientWidth; }
    return w;
    }
    function getH(){
    var h;
    if(document.innerHeight){ h=document.innerHeight;
    } else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
    } else if(document.body){ h=document.body.clientHeight; }
    return h;
    }
    Edit:
    i'm returning the value into a Math.random()*getH();
    i'm using the value from that to randomly position a single character on the page.
    hope that helps :S
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    html, body {
    margin:0;
    padding:0;
    border:0;
    text-align:center;
    }
    </style>
    <script type="text/javascript">
    <!--
    function getW(){
    var w;
    if(document.innerWidth){ w=document.innerWidth;
    } else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
    } else if(document.body){ w=document.body.clientWidth; }
    return w;
    }
    function getH(){
    var h;
    if(document.innerHeight){ h=document.innerHeight;
    } else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
    } else if(document.body){ h=document.body.clientHeight; }
    return h;
    }
    function showMe(){
    alert(getH());
    alert(getW());
    }
    //-->
    </script>
    </head>
    
    <body>
    <form action="#" method="post">
    <div>
    <input type="button" onclick="showMe()" value="Show Me">
    </div>
    </form>
    </body>
    </html>
    It seems to be returning correctly. IE does have a border on the body so you need to set that to 0 as well. You may want to get this FF extension called MeasureIt which allows you to draw out a ruler in your FF browser. I've attached an SS with an alert and the Ruler drawn. They seem to match.
    Attached Thumbnails Attached Thumbnails return client height / width.-height.jpg  
    Last edited by _Aerospace_Eng_; 01-18-2006 at 09:27 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    html, body {
    margin:0;
    padding:0;
    border:0;
    text-align:center;
    }
    </style>
    <script type="text/javascript">
    <!--
    function getW(){
    var w;
    if(document.innerWidth){ w=document.innerWidth;
    } else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
    } else if(document.body){ w=document.body.clientWidth; }
    return w;
    }
    function getH(){
    var h;
    if(document.innerHeight){ h=document.innerHeight;
    } else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
    } else if(document.body){ h=document.body.clientHeight; }
    return h;
    }
    function showMe(){
    alert(getH());
    alert(getW());
    }
    //-->
    </script>
    </head>
    
    <body>
    <form action="#" method="post">
    <div>
    <input type="button" onclick="showMe()" value="Show Me">
    </div>
    </form>
    </body>
    </html>
    It seems to be returning correctly. IE does have a border on the body so you need to set that to 0 as well. You may want to get this FF extension called MeasureIt which allows you to draw out a ruler in your FF browser. I've attached an SS with an alert and the Ruler drawn. They seem to match.
    ok, that looks nice - however it's still not working for me.


    http://rlemon.com/assassins/test <-- characters are randomly scattered on the page - reload a couple times with the browser NOT maximized and you'll see scrollbars occasionally.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


  •  

    Posting Permissions

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