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;
}