Time of plugin >>
<< Symbol Coffee House
Get document.body.clientHeight correctly

Author Zhou Renjian Create@ 2006-09-19 17:20
whizz Note icon
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="margin:2px;padding:4px;">
<head>
    <title>Client Area Test</title>
</head>
<body id="body" style="margin:10px;padding:5px;">
<div id="_console_" style="height:100px;"></div><!-- Test: set "height:1200px;" -->
<script type="text/javascript">
// <![CDATA[
var ua = navigator.userAgent.toLowerCase ();
OS = {};
OS.isFirefox = ua.indexOf ("gecko") != -1;
OS.isOpera = ua.indexOf ("opera") != -1;
OS.isIE = !OS.isOpera && ua.indexOf ("msie") != -1;

function getSafeClientHeight () {
    var b = document.body;
    var p = b.parentNode;
    var bcHeight = b.clientHeight;
    var pcHeight = p.clientHeight;
    if (OS.isIE) { // && !OS.isOpera
        return (pcHeight == 0) ? bcHeight : pcHeight;
    } else if (OS.isFirefox) {
        return (pcHeight == p.offsetHeight
                && pcHeight == p.scrollHeight) ? bcHeight : pcHeight;
    }
    return bcHeight;
}

function alert (s) {
    var csl = document.getElementById ("_console_");
    csl.appendChild (document.createTextNode ("" + s));
    csl.appendChild (document.createElement ("br"));
}
alert (document.body.clientHeight);
alert (document.body.scrollHeight);
alert (document.body.offsetHeight);
alert ("=====");
alert (document.body.parentNode.nodeName);
alert (document.body.parentNode.clientHeight);
alert (document.body.parentNode.scrollHeight);
alert (document.body.parentNode.offsetHeight);

alert ("*******");
alert (getSafeClientHeight ());
// ]]>
</script>
</body>
</html>


本记录所在类别:
本记录相关记录: