firefox bug中的Javascript和Doctype
我有以下javascript代码: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
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
在某些情况下返回文档的滚动宽度。请参阅,以获取有关此的规范草案