修改iframe内部元素样式,并且内部内容高度自适应:
<iframe srcdoc="" frameborder="0" id="demo" style="vertical-align:top;width:80%" onload="getIframeDom()"></iframe>
function getIframeDom(){
$("#demo").contents().find("p").css('margin','0');
$("#demo").contents().find("body").css('margin','0');
changeFrameHeight();
}
window.onresize=function(){
changeFrameHeight();
}
function changeFrameHeight(){
var ifm= document.getElementById("demo");
var iheight=$("#demo").contents().find("body").height();
$("#demo").height(iheight);
}