iframe同域或异域下高度自动适应(兼容种浏览器)
来源:互联网 发布:vscode和webstorm 编辑:程序博客网 时间:2024/04/30 18:02
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>iframe自动适应高度</title>
- <script type="text/javascript">
- <!--//
- function sizeFrame() {
- var F = document.getElementById("myFrame");
- if(F.contentDocument) {
- F.height = F.contentDocument.documentElement.scrollHeight; //FF 3.0.11, Opera 9.63, and Chrome
- } else {
- F.height = F.contentWindow.document.body.scrollHeight; //IE6, IE7 and Chrome
- }
- }
- window.onload=sizeFrame;
- //-->
- </script>
- </head>
- <body>
- <iframe width="100%" id="myFrame" src="http://www.a.com" scrolling="no" frameborder="0">同域情况</iframe>
- </body>
- </html>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <script type="text/javascript">
- <!--//
- function sizeFrame() {
- var F = document.getElementById("iframeB");
- if(F.contentDocument) {
- F.height = F.contentDocument.documentElement.scrollHeight; //FF 3.0.11, Opera 9.63, and Chrome
- } else {
- F.height = F.contentWindow.document.body.scrollHeight; //IE6, IE7 and Chrome
- }
- }
- window.onload=sizeFrame;
- //-->
- </script>
- </head>
- <body>
- <iframe id="iframeB" name="iframeB" src="http://www.b.com/test.html" width="100%" height="auto" scrolling="no" frameborder="0"></iframe>
- </body>
- </html>
- <iframe id="iframeA" name="iframeA" src="" width="0" height="0" style="display:none;" ></iframe>
- <script type="text/javascript">
- function sethash(){
- hashH = document.documentElement.scrollHeight; //获取自身高度
- urlC = "http://www.a.com/z.html"; //设置iframeA的src
- document.getElementById("iframeA").src=urlC+"#"+hashH; //将高度作为参数传递
- }
- window.onload=sethash;
- </script>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <script type="text/javascript">
- function pseth() {
- var iObj = parent.parent.document.getElementById('iframeB');//A和main同域,所以可以访问节点
- iObjH = parent.parent.frames["iframeB"].frames["iframeA"].location.hash;//访问自己的location对象获取hash值
- iObj.style.height = iObjH.split("#")[1]+"px";//操作dom
- }
- pseth();
- </script>
- </head>
- <body>
- </body>
- </html>
转载:http://www.cnf2e.com/javascript/iframe-auto-height.html
- iframe同域或异域下高度自动适应(兼容种浏览器)
- 完美解决iframe自动适应高度兼容浏览器
- iframe ie下自动适应高度
- iframe高度自动适应
- iframe自动适应高度
- iframe 高度自动适应
- Iframe自动适应高度
- iframe高度自动适应
- IFRAME 自动适应高度
- Iframe自动适应高度
- iframe自动适应高度
- iframe自动适应高度
- iframe 自动适应高度
- iframe 自动适应高度
- iframe高度自动适应
- iframe高度自动适应
- iframe 自动适应高度
- iframe自动适应高度
- c++二维指针
- 【xinfanqie】认清XP系统默认设置的安全问题
- queue类
- 理解HTTP幂等性
- 【算法导论笔记】所有结点对的最短路径问题
- iframe同域或异域下高度自动适应(兼容种浏览器)
- php hMailServer配置
- spotlight soo5072:there was an error reading the tnsnames.ora
- MongoDB备份与恢复
- Android模拟器源码Qemu Study for Android Emulator
- HTTP方法的幂等性
- ZkUtils 1.2.1版,一个zk开发中的工具方法集合
- MPlayer在ARM开发板的移植
- WCF 的 Web 访问方式