Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
firefox bug中的Javascript和Doctype_Javascript_Firefox_Doctype - Fatal编程技术网

firefox bug中的Javascript和Doctype

firefox bug中的Javascript和Doctype,javascript,firefox,doctype,Javascript,Firefox,Doctype,我有以下javascript代码: function pageWidth() { return (window.innerWidth != null ? window.innerWidth : (document.body != null ? document.body.offsetWidth : null )); } function bodyloaded() { winWidth = p

我有以下javascript代码:

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);
}
并应用于onload和onresize方法中的body标记,问题是如果我放入任何doctype,该代码在firefox上不起作用,但在IE上起作用。 我调试了scrollWidth和offsetWidth的值,并且总是得到相同的值,这是使用Doctype实现的

有解决办法吗

在quirks模式下(无doctype或quirks模式doctype),
document.body.scrollWidth
在某些情况下实际返回文档的滚动宽度,而不是正文。在标准模式下(对于大多数doctype),它返回正文的滚动宽度,
document.documentElement.scrollWidth
在某些情况下返回文档的滚动宽度。请参阅,以获取有关此的规范草案