js iframeページ間呼び出し関数を実現する方法
5978 ワード
この例では、jsがiframeのページ間呼び出し関数を実装する方法について説明します.皆さんの参考にしてください.具体的な実現方法は以下の通りである.
プロジェクトでは、ページにIframeが導入され、親ページがサブページ関数を呼び出す必要があるか、サブページが親ページ関数を呼び出す必要があるという問題が避けられません.例えば、2つのページがあります.htmlとchild.html.ここでparent.htmlにはIframeが含む、Iframeはchildを指す.html.今parentでhtml/child.htmlでchildを呼び出す.html/parent.htmlのjsメソッドです.
具体的なコードは以下のように実現される.
parent.html親ページ:
child.htmlサブページ:
プロジェクトでは、ページにIframeが導入され、親ページがサブページ関数を呼び出す必要があるか、サブページが親ページ関数を呼び出す必要があるという問題が避けられません.例えば、2つのページがあります.htmlとchild.html.ここでparent.htmlにはIframeが含む、Iframeはchildを指す.html.今parentでhtml/child.htmlでchildを呼び出す.html/parent.htmlのjsメソッドです.
具体的なコードは以下のように実現される.
parent.html親ページ:
<html>
<head>
<script type="text/javascript">
function parent_click(){
alert(" ");
}
script>
head>
<body>
<input type="button" value=" " onclick="parent_click();" />
<input type="button" value=" " onclick='window.frames["childPage"].child_click();' />
<iframe id="childPage" name="childPage" src="inner.html" width="100%" frameborder="0">iframe>
body>
html>
child.htmlサブページ:
<html>
<head>
<script type="text/javascript">
function child_click(){
alert(" ");
}
script>
head>
<body>
<input type="button" value=" " onclick='parent.window.parent_click();' />
<input type="button" value=" " onclick="child_click();" />
body>
html>