JS实现iframe自适应高度的方法示例
本文实例讲述了JS实现iframe自适应高度的方法。分享给大家供大家参考,具体如下:
<iframeid="mainFrame"name="mainFrame"src="/zwgk/hsearchview"width="740"frameborder="0"scrolling="no"scrolling="no"frameborder="0"> </iframe>
<scripttype="text/javascript"language="javascript"> functionreinitIframe(){ variframe=document.getElementById("mainFrame"); try{ varbHeight=iframe.contentWindow.document.body.scrollHeight; vardHeight=iframe.contentWindow.document.documentElement.scrollHeight; varheight=Math.max(bHeight,dHeight); iframe.height=height; }catch(ex){} } window.setInterval("reinitIframe()",100); </script>
PS:高度自适应应用广泛,本站的很多在线工具也使用了这一技巧,列举如下几个工具供大家参考:
JavaScript在线格式化工具(基于beautify.js插件):
http://tools.jb51.net/code/js_beautify
在线颜色选择器工具/RGB颜色查询对照表:
http://tools.jb51.net/color/colorpicker
在线个人所得税计算器:
http://tools.jb51.net/jisuanqi/tax_calc
宋词在线查询:
http://tools.jb51.net/bianmin/songci
更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript操作DOM技巧总结》、《JavaScript数组操作技巧总结》、《JavaScript排序算法总结》、《JavaScript遍历算法与技巧总结》、《JavaScript数学运算用法总结》、《JavaScript数据结构与算法技巧总结》、《JavaScript查找算法技巧总结》及《JavaScript错误与调试技巧总结》
希望本文所述对大家JavaScript程序设计有所帮助。