How can I detect a Scrollbar presence ( using Javascript ) in HTML iFrame?

var root= document.compatMode=='BackCompat'? document.body : document.documentElement;
var isVerticalScrollbar= root.scrollHeight>root.clientHeight;
var isHorizontalScrollbar= root.scrollWidth>root.clientWidth;

This detects whether there is a need for a scrollbar. For the default of iframes this is the same as whether there is a scrollbar, but if scrollbars are forced on or off (using the ‘scrolling=”yes”https://stackoverflow.com/”no”’ attribute in the parent document, or CSS ‘overflow: scroll/hidden’ in the iframe document) then this may differ.

Leave a Comment