Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check to see if an iframe has scrollbars visible?

I was wondering if anyone knows how to check to see if the content in an iframe is overflowing and the scrollbars are visible?

Thanks

like image 962
Olokoo Avatar asked Sep 16 '12 04:09

Olokoo


People also ask

How do I check if an iFrame has a scrollbar?

You want to check if the element's scrollHeight is greater than the clientHeight , or if the element's scrollWidth is greater than the clientWidth . This can be done with those properties directly, or by using helper methods provided by jQuery.

Why does my iFrame have a scrollbar?

Content that is presented in an iFrame appears with a vertical scrollbar if the length of the child document exceeds the height of the iFrame and with a horizontal scrollbar if the child document elements won't wrap to the width of the iFrame.


1 Answers

in general you should compare the delta of the element's scrollHeight/scrollWidth and offsetHeight/offsetWidth. if positive then 'we got a winner'. but.. when looking for scrollbars in an iframe, things get a little bit trickier:

var frm=document.getElementById("frm");
var iIsVrScrollBar =  frm.contentWindow.document.documentElement.scrollHeight>frm.contentWindow.document.documentElement.offsetHeight ? 1 : 0;
var iIsHrScrollBar = frm.contentWindow.document.documentElement.scrollWidth>frm.contentWindow.document.documentElement.offsetWidth ? 1 : 0;
like image 61
shayuna Avatar answered Oct 15 '22 22:10

shayuna