现在的解决方法是在不支持跨域
1.当嵌入的网页可以支持提前写入代码 处理步骤
在俩个域名,协议,端口号一致的情况下让iframe高度自适应内容高度
设置 iframe高度
Iframe 嵌套的页面和Iframe父级页面js文件里面上加上document.domain = ’xxxx.com’;
把一级域名设置成一样的
下图是 iframe设置一级域名
下图是iframe 父级页面设置一级域名和控制iframe 高度
$(function() {
document.domain="baidu.cn"
var iframe = document.getElementById('embeddedIframe');
if (iframe.attachEvent) {
iframe.attachEvent("onload", function() {
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight + 30;
});
} else {
iframe.onload = function() {
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight + 30;
};
}
})
2.当嵌入的网页可以不支持提前写入代码 处理步骤
在css样式中写入
#embeddedIframe {
height: 1500px !important;
}