本文介绍了如何在HTML iFrame中检测滚动条存在(使用Javascript)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经尝试过:

  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){
//当theres a scrollbar
} else {
//当theres不是滚动条
}

而且我也尝试过:

  this.scrollLeft = 1; 
if(this.scrollLeft> 0){
//当theres a scrollbar
this.scrollLeft = 0;
} else {
//当theres不是滚动条
返回false;
}

没有成功..



我已经在 DOM检查器上搜索了 javascript objets ,但没有找到任何东西。



是否可以检测javacscript中的iframe中的滚动条存在?






iframe内容来自同一个域。



直到现在没有成功..



解决方案

使用jQuery可以比较文档高度,scrollTop位置和视口高度,这可能会让您得到所需的答案。



以下行:

  $(window).scroll(function(){
if(isMyStuffScrolling()){
//这里有一个滚动条!
}
});

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


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

解决方案

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);
}

这篇关于如何在HTML iFrame中检测滚动条存在(使用Javascript)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:46