简体   繁体   中英

Javascript and Doctype in firefox bug

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM