iframe自适应、iframe跨域自适应

来源:互联网 发布:农村淘宝加盟申请 编辑:程序博客网 时间:2024/05/18 18:43
<iframe id="dataLoad" name="dataLoad" scrolling="no"    frameborder="no" style="border: 0px;" width="980px" height="600px"    marginheight="0" marginwidth="0" frameborder="0"    src="http://localhost:8080/projectName/gis.action?pageType='true'&pwd=<s:property value="shUserInfo.xwh" escape="true" />"></iframe>

本域:
    /**
 /**         * iframe自适应加载         * */        function reSetIframe(){            var iframe = document.getElementById("dataLoad");            iframe.height = 200;              try{                  var bHeight = iframe.contentWindow.document.body.scrollHeight;                  var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;                  var height = Math.max(bHeight, dHeight);                  iframe.height = height+40;              }catch (ex){}        }

跨域:



    中间jsp(agent.jsp同主iframe在相同目录下)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>        <%            String path = request.getContextPath();        %>        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">        <html>            <script>                function pseth() {                    var iObj = parent.parent.document.getElementById("dataLoad");//A和main同域,之所以可以访问节点                    var iObjH = parent.frames["biframe"].location.href;//访问自个儿的location对象获取hash值                    var bHeight = iObjH.split("?")[1];//操作dom                    iObj.style.height = bHeight + "px";                            parent.parent.document.getElementById("container_1000").style.height = (Number(bHeight) + 260)+ "px";                }                pseth();            </script>        </html>

        
    嵌套页面(iframe其他域下的jsp、action)
   
<iframe id="biframe" name="biframe"  width="100%"  src="" style="display:none"></iframe>    function sethash(){            var b_height = document.getElementById("mtjy_con").scrollHeight;            var b_iframe = document.getElementById("biframe");            b_iframe.src =  "http://192.168.1.10:8080/projectName/agent.jsp?"+b_height;        }        window.onload=sethash;


0 0
原创粉丝点击