iframe跨子域

主页面

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

复制代码
<script>
    
//两个页面必须都包含下面的设置,domain设置只支持跨子域
    document.domain = "84ren.com";
    
function test() {
        
//获取正文高度
        document.getElementById("ifm").height = document.getElementById("ifm").contentWindow.document.screen.availHeight;
        
//获取总高度
        //document.getElementById("ifm").height = document.getElementById("ifm").contentWindow.screen.availHeight;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<iframe src="http://test2.dealer.ucar.cn/error.aspx" frameborder="0" scrolling="no" onload="javascript:{test();}" width="960" id="ifm" name="ifm"></iframe>
    
</div>
    
</form>
</body>
</html> 
复制代码

 iframe页面

 只要保证包含document.domain = "84ren.com"即可实现调用

原文地址:https://www.cnblogs.com/zcm123/p/2684965.html