iframe父子页面js之间的调用

 

父级页面:mian.html

子页面1:top.html

子页面2:index.html

页面关系

 <div onclick="_top()">调用contentTop页面的alertTop方法</div>
    <iframe id="contentTop" name="contentTop" frameborder="0" th:src="@{/top}" >
        你不支持iframe
    </iframe>
    <iframe id="contentMain" name="contentMain"  frameborder="0" th:src="@{/index}" >
        你不支持iframe
    </iframe>

 

 

父页面调用子页面的方法 (mian.html调用top.html页面的方法)

js写法 这里的contentTop对应的是iframe的name名

 function _top() {
        contentTop.window.alertTop();
    }

 

 

子页面调用父页面的方法 (top.html调用frame.html的方法)

在top.html页面写

<div id="_click">调用父级页面的show()方法</div>

js写法

$("#_click").on('click',function () {
        parent.show();
    })

 

子页面调用子页面的方法 (top.html调用index.html中的方法)  这有个要求 就是top.html和index.html要同时都显示出来

 <div onclick="_top_index()">调用index.html的_index()方法</div>

js写法 (这里的contentMain对应的是frame.html中index.html的name名)

function _top_index() {
        parent.contentMain._index();
    }

 

posted @ 2021-10-08 14:08  yvioo  阅读(1609)  评论(0编辑  收藏  举报