Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

I have already tried :

        var vHeight = 0;         if (document.all) {           if (document.documentElement) {             vHeight = document.documentElement.clientHeight;           } else {             vHeight = document.body.clientHeight           }     } else {       vHeight = window.innerHeight;     }      if (document.body.offsetHeight > vHeight) {       //when theres a scrollbar     }else{       //when theres not a scrollbar     } 

And I also had tried :

           this.scrollLeft=1;     if (this.scrollLeft>0) {         //when theres a scrollbar         this.scrollLeft=0;         }else{         //when theres not a scrollbar         return false;     } 

With no success..

I have searched the javascript objets on DOM Inspector, but didn't find anything.

Is is possible to detect a scrollbar presence in a iframe in javacscript ?


The iframe content comes from the same domain.

No success until now..

alt text http://www.upvtp.com.br/file.php/1/help_key.jpg

like image 789
Bonfocchi Avatar asked Mar 25 '09 10:03

Bonfocchi


1 Answers

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"/"no"’ attribute in the parent document, or CSS ‘overflow: scroll/hidden’ in the iframe document) then this may differ.

like image 159
bobince Avatar answered Sep 20 '22 14:09

bobince