[英]Detect scrollbars within iFrame JS
My webpage has an embedded iFrame which is using a 3rd party tool within my webpage which means the URL from the iFrame is coming from a different location. 我的网页上有一个嵌入式iFrame,该网页中使用的是第三方工具,这意味着来自iFrame的URL来自其他位置。
I need to detect the presentation of a scroll bar within the iFrame window when resizing the page, then carrying out a task once it has been detected. 调整页面大小时,我需要在iFrame窗口中检测滚动条的呈现,然后在检测到任务后执行任务。
I have tried a variety of different solutions all which have not been successful. 我尝试了各种不同的解决方案,但都没有成功。
Is this possible? 这可能吗?
Many Thanks! 非常感谢!
This is the first thing that comes to my mind: http://jsfiddle.net/matias/hhcKn/ 这是我想到的第一件事: http : //jsfiddle.net/matias/hhcKn/
just sample code! 只是示例代码!
HTML: HTML:
<div id="body"></div>
JS: JS:
var $iframe = $("<iframe></iframe>").appendTo("#body");
var iframe = $iframe[0];
var doc = iframe.document;
//test this
var content = "<h1>Hello world</h1><br><p>more content!</p>";
//and then this
//var content = "<h1>Hello world</h1><br><br><br><br><br><p>more content!</p>";
if(iframe.contentDocument){
doc = iframe.contentDocument;
}
else if(iframe.contentWindow){
doc = iframe.contentWindow.document;
}
doc.open();
doc.writeln(content);
doc.close();
//this is the part that might interest you
var div_height = $("#body").height();
var iframe_height = $("iframe").contents().height();
if(iframe_height > div_height) alert("scrollbars present");
CSS: CSS:
body{
border: 1px solid red;
}
iframe{
border: none;
}
<iframe src="111.html" id="iframeid" height="300" width="800"></iframe>
<script type="text/javascript">
function resizeIFrame(){
$("#iframeid").attr("height", $("#iframeid").contents().height());
}
setInterval("resizeIFrame()", 500)
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.