iframe中子页面父页面里函数互调

在iframe中很多要用的子页面父页面函数互调的情况,下面看一下各自用法,本人写个人网站的时候用过其他场景尚未试过

子页面调父页面

function fu(){

    alert('父');    
}
function zi(){

    parent.fu();    
}
父页面掉子页面
<iframe name="myFrame" src="child.html"></iframe> 
function fu(){
    myFrame.window.zi();
}

function zi(){
    alert('子');

}

 iframe自适应高度

$("#iframe").load(function(){
    var mainheight = $(this).contents().find("body").height()+30;
    $(this).height(mainheight);
});

 判断是否是iframe 页面中

if(window.location.href == top.location.href){
    //不在iframe中
}else{
    //在iframe中
}

 去掉iframe 的边框 滚动条,IE8下黑色边框,加下面属性

scrolling="no" frameborder="0"
原文地址:https://www.cnblogs.com/bruce-gou/p/5231231.html