Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  179] [ 7]  / answers: 1 / hits: 47640  / 16 Years ago, wed, march 25, 2009, 12:00:00

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


More From » html

 Answers
24

Using jQuery you can compare the document height, the scrollTop position and the viewport height, which might get you the answer you require.



Something along the lines of:



$(window).scroll(function(){
if(isMyStuffScrolling()){
//There is a scroll bar here!
}
});

function isMyStuffScrolling() {
var docHeight = $(document).height();
var scroll = $(window).height() + $(window).scrollTop();
return (docHeight == scroll);
}

[#99797] Thursday, March 19, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
viridianaw

Total Points: 154
Total Questions: 94
Total Answers: 89

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
;