Difference:
body is the body sub-node in the DOM object, that is, the
tag;
documentElement is the root node of the entire node tree, that is, the tag;
When DTD is not used, that is, in weird mode BackCompat:
document .documentElement.clientHeight=0document.body.clientHeight=618
When using DTD, that is, under standard mode CSS1Compat:
document.documentElement.clientHeight=618 document.body.clientHeight=28 (indicating the height of the content)
So extract the browse The size of the device should be noted. You can refer to the following code:
if (document.compatMode == "BackCompat") {
cWidth = document.body.clientWidth;
cHeight = document.body.clientHeight;
sWidth = document.body.scrollWidth;
sHeight = document.body.scrollHeight;
sLeft = document.body.scrollLeft;
sTop = document.body.scrollTop;
}
else { //document.compatMode == "CSS1Compat"
cWidth = document.documentElement.clientWidth ;
cHeight = document.documentElement.clientHeight;
sWidth = document.documentElement.scrollWidth;
sHeight = document.documentElement.scrollHeight;
sLeft = document.documentElement.scrollLeft == 0 ? document. body.scrollLeft : document.documentElement.scrollLeft;
sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop;
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn