Scroll bar detection in iFrame JS

An iFrame is built into my webpage, which uses a third-party tool on my webpage, which means that the URL from the iFrame comes from a different place.

I need to determine the representation of the scroll bar in the iFrame when the page is resized, and then complete the task after it is detected.

I tried various solutions that were not successful.

Is it possible?

Thank you very much!

+4
source share
2 answers

This is the first thing that comes to my mind: http://jsfiddle.net/matias/hhcKn/

just a sample code!

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; } 
+1
source
 <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> 
+1
source

All Articles