如何检测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) {
      //when theres a scrollbar
    }else{
      //when theres not a scrollbar
    }和我也尝试过:
           this.scrollLeft=1;
    if (this.scrollLeft>0) {
        //when theres a scrollbar
        this.scrollLeft=0;
        }else{
        //when theres not a scrollbar
        return false;
    }没有成功..。
我已经搜索了DOM检查器上的javascript视图,但是没有找到任何东西。
是否可以在javacscript中的iframe中检测到滚动条的存在?
iframe内容来自同一个域。
直到现在还没有成功..。
alt text http://www.upvtp.com.br/file.php/1/help_key.jpg
发布于 2009-03-25 11:04:19
使用jQuery,您可以比较文档高度、scrollTop位置和视口高度,这可能会得到所需的答案。
与…有关的东西:
$(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);
} 发布于 2009-03-25 14:03:29
var root= document.compatMode=='BackCompat'? document.body : document.documentElement;
var isVerticalScrollbar= root.scrollHeight>root.clientHeight;
var isHorizontalScrollbar= root.scrollWidth>root.clientWidth;这将检测是否需要滚动条。对于iframes的默认情况,这与是否存在滚动条是一样的,但是如果滚动条被强制打开或关闭(在父文档中使用‘scrolling=“”yes“/”no“属性,或者在iframe文档中使用CSS’overflow:滚动/隐藏‘),那么这可能有所不同。
发布于 2010-08-19 00:33:28
$(window).scroll(function(){
  if(isMyStuffScrolling()){
//scrolling
  }else{
//not scrolling
}
}); 
function isMyStuffScrolling() {
  var docHeight = $(document).height();
  var scroll    = $(window).height() ;//+ $(window).scrollTop();
  if(docHeight > scroll) return true;
  else return false;
}改进--从Jon`s代码中略作修改
https://stackoverflow.com/questions/681087
复制相似问题