javascript - 如何检测iframe内页面的高度?

标签 javascript html

我的页面中有一个 iframe

<iframe src="page.aspx" > 

我不知道这件事会有多大。如何获取高度?由于浏览器的差异,jquery 在这里可能会很好。

// sth like this. 
currentfr.contentDocument.body.offsetHeight // NS 
currentfr.Document.body.scrollHeight // IE 

最佳答案

喜欢您的代码,但您对其进行了一些增强以避免错误

if (window.innerWidth) { //if innerWidth is defined
      // the standard
      w = fr.width,
      h = fr.height
 }
else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
       // IE6
       w = fr.document.documentElement.clientWidth,
       h = fr.document.documentElement.clientHeight
}

关于javascript - 如何检测iframe内页面的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2362565/

相关文章:

Javascript d3 : Is there a way to programmatically stop dragging an item?

javascript - 我应该如何使用 bacon.js 保存多个值的运行总计?

javascript - 是否可以在 Google 条形图上放置趋势线?

html - 菜单不会位于视差图像之上

html - 复选框转换无法正常工作

javascript - 在 Microsoft Windows 上,当使用 HTML5 拖放时,在拖放过程中我确实看到了拖动图标(幻影)

javascript - 使用 HTML 输出标签查看可缩放图像并分配 src

html - 固定 HTML 表格中的特定行或列

html - 何时使用超大屏幕?

javascript - 在dom元素中插入span而不覆盖子节点?