簡體   English   中英

檢測iFrame JS中的滾動條

[英]Detect scrollbars within iFrame JS

我的網頁上有一個嵌入式iFrame,該網頁中使用的是第三方工具,這意味着來自iFrame的URL來自其他位置。

調整頁面大小時,我需要在iFrame窗口中檢測滾動條的呈現,然后在檢測到任務后執行任務。

我嘗試了各種不同的解決方案,但都沒有成功。

這可能嗎?

非常感謝!

這是我想到的第一件事: http : //jsfiddle.net/matias/hhcKn/

只是示例代碼!

HTML:

<div id="body"></div>

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:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM