How to find out width and height of viewpoint in browser window? And How to find out how much document scrolled to down and to right?
            Asked
            
        
        
            Active
            
        
            Viewed 5,698 times
        
    5
            
            
        - 
                    And How to find out how much document scrolled to down and to right? – xXx Dec 07 '09 at 15:05
- 
                    Try reading any one of these: http://stackoverflow.com/questions/871399/cross-browser-method-for-detecting-the-scrolltop-of-the-browser-window http://stackoverflow.com/questions/1248081/get-the-browser-viewport-dimensions-with-javascript http://stackoverflow.com/questions/817446/good-way-to-estimate-available-browser-area – random Dec 07 '09 at 15:06
2 Answers
7
            Try this function... and call it when needed :)
function getViewPortSize()
{
    var viewportwidth;
    var viewportheight;
    //Standards compliant browsers (mozilla/netscape/opera/IE7)
    if (typeof window.innerWidth != 'undefined')
    {
        viewportwidth = window.innerWidth,
        viewportheight = window.innerHeight
    }
    // IE6
    else if (typeof document.documentElement != 'undefined'
    && typeof document.documentElement.clientWidth !=
    'undefined' && document.documentElement.clientWidth != 0)
    {
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
    }
    //Older IE
    else
    {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    return viewportwidth + "~" + viewportheight;
}
 
    
    
        Juanra
        
- 88
- 5
0
            
            
        height = document.body.clientHeight;
width = document.body.clientWidth;
regarding scroll position, I'm not sure if there is a standard way of determining that, however this should work in most browsers:
scrolled = document.body.scrollTop;
 
    
    
        Sune Rievers
        
- 2,676
- 3
- 25
- 29
