不同浏览器的document.body.offsetWidth变体 [英] document.body.offsetWidth variations for different browsers

查看:140
本文介绍了不同浏览器的document.body.offsetWidth变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

document.body.offsetWidth返回firefox中垂直滚动条左侧到左侧的内部值。
在IE中它不是,而是从左侧返回到垂直滚动条的右侧。
有没有人知道我可以做一个合理的方式,比如var = offsetw;为offsetw是滚动条宽度我需要扣除以获得像document.body.innerWidth值的火狐?
Heres what's。

document.body.offsetWidth returns the innerwidth value from left hand side to the left side of the vertical scrollbar in firefox. In IE it doesn't, instead it returns from left hand side to the right side of the vertical scrollbar. Does anyone know a sensible way I could make a veriable such as "var = offsetw;" for offsetw to be the scrollbar width I need to subtract to get a firefox like document.body.innerWidth value? Heres what I have.

if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
        winW = 16;
        winH = 16;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
        winW = 20;
        winH = 20;
    }
    if (navigator.appName.indexOf("Mozilla")!=-1){
        winW = 0;
        winH = 0;
    }
}

Firefox目前使用16值而不是零声明通过Mozilla行,这表明它是错误的。

Firefox currently uses the 16 value and not the zero declared by the Mozilla line, which indicates it is wrong.

我添加或修复后,为每个浏览器获取winW和winH到正确大小的滚动条如果这些浏览器不自动从document.body.offsetWidth减去滚动条

I'm after an addition or fix to get winW and winH to the correct size of the scrollbar for each browser only if those browsers don't subtract the scrollbar from document.body.offsetWidth automatically

感谢:)

推荐答案


document.body.offsetWidth返回firefox中垂直滚动条左侧到左侧的内部值。

document.body.offsetWidth returns the innerwidth value from left hand side to the left side of the vertical scrollbar in firefox.

不适合我,它不会返回与IE,Opera,Konqueror和Safari相同的值。示例代码?

Not for me it doesn't, it returns the same value as IE, Opera, Konqueror and Safari. Example code?

由appName嗅探浏览器在最好的时候非常不可靠,无论如何不会在这种情况下覆盖它,因为滚动条的大小更受操作系统和用户首选项比浏览器。

Sniffing browser by appName is very unreliable at the best of times and doesn't cover it in this case anyway because the size of a scrollbar is influenced more by operating system and user preferences than the browser.

相反,如果您想要读取'内部大小',请使用clientWidth / clientHeight而不是offsetWidth / offsetHeight,或者测量一个块内的滚动条的offsetWidth。

Instead, if you want to read the ‘inside size’, use clientWidth/clientHeight instead of offsetWidth/offsetHeight, or measure the offsetWidth of a block inside the one with the scrollbar.

这篇关于不同浏览器的document.body.offsetWidth变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆