document和window height返回相同的值
document and window height return the same value?
由于某些原因,文档高度和窗口高度都返回相同的值,因此从文档高度减去窗口时返回0。有人知道为什么会发生这种事吗?
console.log($(window).height());
console.log($(document).height());
以上两者都返回文档高度
您可能忘记了页面开头的doctype <!DOCTYPE html>
。
这是因为文档填充了视口(可用于显示文档的区域)。
来自文件:
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
如果文档的长度足以占用多个页面,则第二个值可能大于第一个值(至少如果文档位于iframe中,请查看此演示)。可能还有其他情况会产生差异,但我现在没有想到。
我遇到了类似的问题,我能够解决。我发现
$(window).height();
正在返回FF中页面的整个高度。最终,我意识到我在页面的任何html之前都输出了一个调试短语"test"。文档类型前的IE。
删除此"测试"文本后,视图端口高度将按预期返回。
相关文章:
- $(document).height和$(window).heaght都返回相同的值-使用的是正确的doctype
- WebView返回错误的window.innerHeight
- document和window height返回相同的值
- 如何在提示下获取和使用从window.onbeforeunload事件的返回语句显示的值
- window.open在chrome扩展中返回undefined
- Reg-ex,用于解析window.location.pathname并返回个/s
- JavaScript window.location.search.substr(1)以空字符串形式返回
- window.safari.pushNotification.requestPermission总是返回"拒绝
- window.frames.length在chrome和Firefox浏览器中返回0
- 在浏览器返回时使window.history.state null的可能情况是什么
- 如何从保留换行符的 window.prompt() 返回文本
- 为什么 $(window).resize() 没有在此代码段中触发或返回错误
- parent.window.location.pathname 返回未定义
- 火狐返回假;(防止默认();)和 window.location.reload();一起
- window.getSelection() 返回意外的值
- $(window).height() 返回奇怪的值
- 获取 window.location.href 以返回页面名称和扩展名(如果 URL 以 / 斜杠结尾)
- Javascript - window.getComputedStyle 返回 “auto” 作为元素顶部和左侧属性
- window.height和document.height返回相同的值
- 返回window.history.pushState之后的第一个状态