4

私はこのJqueryを初めて使用しますが、外部Webページをホストしている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();
}

助けてください。

4

1 に答える 1

0

以下のコードを試してください...それはあなたを助けます....それは私にとって完璧に機能します...

<!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>
于 2013-01-23T06:52:36.363 に答える