IFrame跨域访问&&IFrame跨域访问自定义高度

1.IFrame跨域访问:

http://blog.csdn.net/fdipzone/article/details/17619673

2.IFrame跨域访问自定义高度:

由于JS禁止跨域访问,如何实现不同域的子页面将高度返回给父页面本身,是解决自定义高度的难点。

JS跨域访问问题描述:应用A访问应用B的资源,由于A,B应用分别部署在不同应用服务器(tomcat)上,属于不同域,JS禁止跨域访问。

解决方案:使用一个连接A,B应用的桥梁页面bradge.jsp来解决。

准备:

应用A localhost:8080

主页面:main.jsp/html

<div class="information_box" style="display:block;">
<iframe id="frame_content"  name="frame_content" src="http://localhost:8888/applicationB/jsp/invokeB.jsp" width="100%" height="0" scrolling="no" frameborder="0"></iframe>
</div> 

连接A,B应用的页面:bradge.jsp/html

<script>
function  pseth() { 
    var iObj = parent.parent.document.getElementById('frame_content');
    iObjH = parent.parent.frames["frame_content"].frames["iframeC"].location.hash; 
    iObj.style.height = iObjH.split("#")[1]+"px"; 
    //alert('bridge');
}
pseth();
</script>

应用B localhost:8888

invokeB.jsp/html

<div id="crossDomain">
<iframe id="iframeC" name="iframeC" src="" width="0" height="0" style="display:none;" ></iframe>
</div>

<script>
function newIframe(){
    $("#iframeC").remove();
    hashH = document.documentElement.scrollHeight; 
    $("#crossDomain").html("<iframe id='iframeC' name='iframeC' src='http://localhost:8080/applicationA/jsp/bradge.jsp#"+hashH+"' width='0' height='0' style='display:none;'></iframe>");
    
    
}
function sethash(){
    newIframe();
}
sethash();
</script>

 

posted on 2017-01-16 15:19  百东  阅读(281)  评论(0编辑  收藏  举报

导航