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

Javascript 如何找到Iframe内容的滚动高度和滚动宽度?,javascript,jquery,Javascript,Jquery,我是这个Jquery的新手,当iframe托管外部网页时,我很难找到iframe scrollheight和scrollwidth。 我尝试了以下代码,但它不工作,我搜索了很多 $.fn.hasVerticalScrollbar = function () { // This will return true, when the div has vertical scrollbar return $frame[0].document.documentElement.offsetH

我是这个Jquery的新手,当iframe托管外部网页时,我很难找到iframe scrollheight和scrollwidth。 我尝试了以下代码,但它不工作,我搜索了很多

$.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>

函数Sam()
{
var iFrameID=document.getElementById('idIframe');
var hashorizontalcroll=iFrameID.contentWindow.document.body.scrollWidth>iFrameID.contentWindow.document.body.clientWidth;
var hasverticalcroll=iFrameID.contentWindow.document.body.scrollHeight>iFrameID.contentWindow.document.body.clientHeight;
警报(“Horiz:+hasHorizontalScroll”);
警报(“Verti:+hasVerticalScroll”);
}
您的浏览器不支持iFrame


您是否试图访问iFrame中的内容?我需要确定iFrame是否有滚动条。。无法访问内容..我目前面临着同样的问题,如果页面托管在其他地方,我不确定您提供的代码是否有效。