跨域方法:

第一步,在主页面里插入代码:
//假设主域名是www.aaa.com  需要插入的跨域域名为www.bbb.com

<iframe src="http://www.bbb.com/index.html" width="100%" height="100%" ></iframe>

<script type="text/javascript">
function iFrameHeight() {
var iObj = parent.parent.document.getElementById('iframepage');
iObjH = parent.parent.frames["iframepage"].frames["MiddleIframe"].location.hash;
iObj.style.height = iObjH.split("#")[1] + "px";
}	
</script>


第二步,在跨域页面里(http://www.bbb.com/index.html)插入代码:
//需要在www.aaa.com下新建一个分目录/kuayu下的autoheight.html空文件,否则如果在根目录下建立html文件不确定会不会成功!

<iframe ></iframe>
<script type="text/javascript">
function on_Height(){
  hashH = document.documentElement.scrollHeight; 
  urlC = "/kuayu/autoheight.htm";
  document.getElementById("MiddleIframe").src=urlC+"#"+hashH; 
}
</script>

 

 

同域名下方法:

只需一步即可:

<iframe src="/abc/default.htm" ></iframe>
<script type="text/javascript">
function iFrameHeight() { 
  var ifm= document.getElementById("iframepage"); 
  var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument; 
  if(ifm != null && subWeb != null) { 
    ifm.height = subWeb.body.scrollHeight; 
  } 
}
</script>

  

 

相关文章:

  • 2021-11-04
  • 2021-11-04
  • 2018-05-31
  • 2021-11-05
  • 2021-10-19
  • 2021-11-14
  • 2021-09-12
猜你喜欢
  • 2021-10-18
  • 2021-11-04
  • 2021-09-14
  • 2021-08-27
  • 2021-11-04
  • 2021-11-04
  • 2021-04-15
  • 2021-08-01
相关资源
相似解决方案