Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Getting Javascript Height, Width, Scrollbar position for all browser

leave a comment »

Following is the script for the above thing

 

function f_clientWidth() {
    return f_filterResults (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
    );
}
function f_clientHeight() {
    return f_filterResults (
        window.innerHeight ? window.innerHeight : 0,
        document.documentElement ? document.documentElement.clientHeight : 0,
        document.body ? document.body.clientHeight : 0
    );
}
function f_scrollLeft() {
    return f_filterResults (
        window.pageXOffset ? window.pageXOffset : 0,
        document.documentElement ? document.documentElement.scrollLeft : 0,
        document.body ? document.body.scrollLeft : 0
    );
}
function f_scrollTop() {
    return f_filterResults (
        window.pageYOffset ? window.pageYOffset : 0,
        document.documentElement ? document.documentElement.scrollTop : 0,
        document.body ? document.body.scrollTop : 0
    );
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

.csharpcode-wrapper, .csharpcode-wrapper pre {
background-color: #f4f4f4;
border: solid 1px gray;
cursor: text;
font-family: Consolas, ‘Courier New’, Courier, Monospace;
font-size: 8pt;
line-height: 12pt;
margin: 20px 0px 10px 0px;
max-height: 200px;
overflow: auto;
padding: 4px 4px 4px 4px;
width: 97.5%;
}
.csharpcode-wrapper pre {
border-style: none;
margin: 0px 0px 0px 0px;
overflow: visible;
padding: 0px 0px 0px 0px;
}
.csharpcode, .csharpcode pre, .csharpcode .alt {
background-color: #f4f4f4;
border-style: none;
color: black;
font-family: Consolas, ‘Courier New’, Courier, Monospace;
font-size: 8pt;
line-height: 12pt;
overflow: visible;
padding: 0px 0px 0px 0px;
width: 100%;
}
.csharpcode pre {
margin: 0em;
}
.csharpcode .alt {
background-color: white;
}
.csharpcode .asp {
background-color: #ffff00;
}
.csharpcode .attr {
color: #ff0000;
}
.csharpcode .html {
color: #800000;
}
.csharpcode .kwrd {
color: #0000ff;
}
.csharpcode .lnum {
color: #606060;
}
.csharpcode .op {
color: #0000c0;
}
.csharpcode .preproc {
color: #cc6633;
}
.csharpcode .rem {
color: #008000;
}
.csharpcode .str {
color: #006080;
}

Advertisements

Written by Manish

April 23, 2007 at 1:34 pm

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: