Thursday, October 4, 2007

JavaScript: Doctype messing up script

Q: If you have the doctype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
, the DOMWindowGetYOffset() + DOMWindowGetInnerHeight() - DOMElementGetHeight(o) returns absolute bottom of document.
A: Internet Explorer in a "Strict" mode reallocate some properties from document.body to document.documentElement.
You should change that functions, like:
function DOMWindowGetYOffset() {
if (window.pageYOffset)
// all except Explorer
{
return window.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict mode
{
return document.documentElement.scrollTop;
}
else if (document.body)
// all other Explorers
{
return document.body.scrollTop;
}
}
quirksmode.org

No comments: