gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:49:09 24 4
gpt4 key购买 nike

我是这个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com