A項目(簡稱A:http://IP:8888/A)跨域訪問B項目(簡稱B:http://IP:8080/B),IP不同實現頁面嵌套與跨域訪問方法問題
1.A(a.jsp) 加載B(b.jsp)
解決方案:
a.jsp中創建iframe
<iframe id="crm_iframepage" width="100%" height="98%" src="http://IP:8080/B/b.jsp" runat=server ></iframe>
2.B(b.jsp)訪問A(a.jsp)的方法
解決方案:
在B中b.jsp頁面中使用js創建iframe對象,引入A中的中間頁面a1.jsp
<script type="text/javascript">
var exec_obj = document.createElement('iframe');
exec_obj.name = 'tmp_frame';
exec_obj.src = 'http://IP:8888/A/a1.jsp?aa=bb'; //可以訪問controller攜帶參數
exec_obj.style.display = 'none';
document.body.appendChild(exec_obj);
</script>
在a1.jsp頁面中
<script type="text/javascript">
/*
*調用的方法是a.jsp頁面的abc方法,參數:aa
*/
$(function(){
parent.parent.abc('${aa}');
});
</script>
我只嘗試了通過B中b.jsp頁面訪問A中的controller,然后中轉到指定頁面(A的a1.jsp),指定頁面在訪問相同域(A)中a.jsp方法
下面是參考資料:
https://www.cnblogs.com/boystar/p/6909214.html
https://www.cnblogs.com/HtmlCss3/p/6184252.html
