1

i have this javascript code :

function pageWidth() {
    return (window.innerWidth != null
        ? window.innerWidth
        : (document.body != null
            ? document.body.offsetWidth
            : null
    ));
}

function bodyloaded() {
    winWidth = pageWidth();
    window.scroll(0, 0);
    scrAmount = Math.floor(
        ((document.body['scrollWidth'] - document.body.offsetWidth)/2) + 8
    );
    scrollBy(scrAmount, 0);
}

and is applied on body tags in methods onload and onresize , the problem is if i put any doctype , this code doesnt work on firefox but works on IE. I debug the value of scrollWidth and offsetWidth , and allways get the same value , this happend using a Doctype.

Any solution?

hugomg
  • 68,213
  • 24
  • 160
  • 246

1 Answers1

3

In quirks mode (no doctype or a quirks mode doctype), document.body.scrollWidth actually returns the scrollWidth of the document instead of the body in some cases. In standards mode (with most doctypes), it returns the scrollWidth of the body, and document.documentElement.scrollWidth returns the scrollWidth of the document in some cases. See http://dev.w3.org/csswg/cssom-view/#dom-element-scrollwidth for the spec draft for this.

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55