回答
你要检查元素的scrollHeight
比clientHeight
更大,如果该元素的scrollWidth
比clientWidth
更大。这可以直接使用这些属性来完成,或者使用jQuery提供的帮助器方法来完成。
If the element's content generated a vertical scrollbar, the scrollHeight value is equal to the minimum clientHeight the element would require in order to fit all the content in the viewpoint without using a vertical scrollbar. When an element's content does not generate a vertical scrollbar, then its scrollHeight property is equal to its clientHeight property. This can mean either the content is too short to require a scrollbar or that the the element has CSS style overflow value of visible (non-scrollable).
一般来说,你应该比较元素的scrollHeight属性/ scrollWidth和的offsetHeight/offsetWidth的三角洲。 如果积极,那么'我们得到了胜利者'。寻找在iframe滚动条时 但..,事情变得有些棘手:
var frm=document.getElementById("frm");
var iIsVrScrollBar = frm.contentWindow.document.documentElement.scrollHeight>frm.contentWindow.document.documentElement.offsetHeight ? 1 : 0;
var iIsHrScrollBar = frm.contentWindow.document.documentElement.scrollWidth>frm.contentWindow.document.documentElement.offsetWidth ? 1 : 0;
您应该补充说明,只有当iframe src来自与托管它的网页相同的来源时,它才起作用。一个示例错误是:“Uncaught SecurityError:阻止了一个源于”http:// ...“的框架访问源于”https:// .....“的框架。请求访问的帧具有“http”的协议,被访问的帧具有“https”的协议。协议必须匹配。 – gae123
我不得不修改代码来得到它的工作。
1)IFRAME &内容都在同一网站/文件夹结构
2)的过程由“sizewindow”设置为TRUE
3策动)它片断是一个计时器功能集的一部分在上IE11测试ANOUT0.5秒
4),FF34 & 35,铬31 & 40,&歌剧12.6
5)活性ç颂大小的窗口,只比含量多,
看到http://www.users.waitrose.com/~cresby/map2.htm
if (sizewindow){
if(iIsVrScrollBar==1) {
frm.style.height = (frm.contentWindow.document.body.offsetHeight+20);
iIsVrScrollBar = (frm.scrollWidth!=frm.contentWindow.document.documentElement.scrollWidth) ? 1 : 0;
if(iIsVrScrollBar==0) sizewindow=false;
}else{
frm.style.height = (frm.contentWindow.document.body.offsetHeight-10);
iIsVrScrollBar = (frm.scrollWidth!=frm.contentWindow.document.documentElement.scrollWidth) ? 1 : 0;
if(iIsVrScrollBar==1) {frm.style.height = (frm.contentWindow.document.body.offsetHeight+10);}
}
}
- 1. Vaadin 7如何检查滚动条是否可见
- 2. 如何检查滚动条是否可见?
- 3. 是否有可能查询WebBrowser控件水平滚动条是否可见?
- 4. 滚动条在iframe中不可见
- 5. 检查滚动条是否可以在WebBrowser中集中/滚动
- 6. 滚动型:检查是否视图是在屏幕上可见或不可见
- 7. 滚动条可见
- 8. wp7:如何检查进度条是否可见或不可见?
- 9. 检查UIAlertView是否可见
- 10. 使垂直滚动条可见和水平滚动条可见
- 11. 是否可以自动滚动iFrame?
- 12. 如何检查ScrollView是否可滚动
- 13. jquery检查是否有任何父div有滚动条
- 14. 检查滚动条是否向下滚动一半
- 15. 检查Windows窗体滚动条是否一直向下滚动?
- 16. 使滚动条总是可见的UIScrollView
- 17. slimscroll滚动条是不可见的
- 18. 滚动条可见,不能滚动
- 19. Iframe没有滚动条?
- 20. 没有滚动条的IFrame
- 21. 检查滚动条
- 22. 如何知道CWnd滚动条是否可见?
- 23. 检测窗体的滚动条是否在mdi子项中可见
- 24. 是否可以从iframe中检测父级滚动?
- 25. 我怎样才能检查一个窗口是否有可见的滚动条使用他的HWND?
- 26. 滚动型可见查看
- 27. 检查UITableViewCell是否完全可见
- 28. iOS - 检查MFMessageComposeViewController当前是否可见
- 29. 检查表单组是否可见
- 30. 检查div是否可见与jQuery
请问这种方法需要的iframe的内容在同一台服务器上托管的,也可以是跨域? – Olokoo
它可以是因为iframe元素在您的域中。内容不是(必然),但内容将最终定义iframe的scrollWidth和scrollHeight,否则无关紧要。 – jimp
我试过这个,但它不起作用,我得到了相同的结果,它们都是元素的高度。 \t \t function checkScroll(){ \t \t \t var intElemScrollHeight = document.getElementById('websiteView')。scrollHeight; \t \t \t var intElemClientHeight = document.getElementById('websiteView')。clientHeight; \t \t \t alert(intElemScrollHeight); \t \t \t alert(intElemClientHeight); \t \t} – Olokoo