javascript - 如何找到Iframe内容的滚动高度和滚动宽度?

标签 javascript jquery

我是这个 Jquery 的新手,当 iframe 托管外部网页时,我很难找到 iframe 的滚动高度和滚动宽度。 我尝试了以下代码,但它不起作用,并且我搜索了很多。

$.fn.hasVerticalScrollbar = function () {
    // This will return true, when the div has vertical scrollbar
    return $frame[0].document.documentElement.offsetHeight() > this.height();
  }
  $.fn.hasHorizontalScrollbar = function () {
    // This will return true, when the div has horizontal scrollbar
    return $frame[0].document.documentElement.offsetWidth() > this.width();
}

请帮忙。

最佳答案

尝试下面的代码...它将帮助您...它非常适合我...

<!DOCTYPE html>
<html>

<script>
function Sam()
{
var iFrameID = document.getElementById('idIframe');
var hasHorizontalScroll= iFrameID.contentWindow.document.body.scrollWidth>iFrameID.contentWindow.document.body.clientWidth;
var hasVerticalScroll= iFrameID.contentWindow.document.body.scrollHeight>iFrameID.contentWindow.document.body.clientHeight;

alert(" Horiz : " + hasHorizontalScroll);
alert(" Verti : " + hasVerticalScroll);
}
</script>
<body>

<iframe src="http://www.w3schools.com" id="idIframe">
  <p>Your browser does not support iframes.</p>
</iframe>

<input type="button" value="find" onclick="Sam();">

</body>
</html>

关于javascript - 如何找到Iframe内容的滚动高度和滚动宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14473835/

相关文章:

javascript - 我怎样才能解析这个xml字符串呢?

javascript - 从 colorbox 重定向到另一个页面

php - 使用mysql在php中通过AJAX实时检查用户名是否存在

JQuery .scrollTop() 计算的长时间延迟

javascript - ScrollMagic 引脚在 TimelineMax 中不起作用

jquery - 需要覆盖内联 css

javascript - 如何在 Microsoft CRM 2011 中根据出生日期计算年龄(以年和月为单位)

php - 自定义复选框在选中时不显示图像

javascript - 标记化字符串的正则表达式

javascript - 如何启用表单中的提交按钮?