欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實現(xiàn)iframe跨頁面調用函數(shù)的方法

 更新時間:2014年12月13日 11:55:35   投稿:shichen2014  
這篇文章主要介紹了js實現(xiàn)iframe跨頁面調用函數(shù)的方法,實例展示了iframe中父頁面調用子頁面和子頁面調用父頁面的實現(xiàn)技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了js實現(xiàn)iframe跨頁面調用函數(shù)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

在項目中難免會遇到這樣一個問題就是頁面引入了IFrame并且需要父頁面調用子頁面函數(shù)或者子頁面需要調用父頁面函數(shù)。比如說:現(xiàn)在有兩個頁面parent.html和child.html。其中parent.html中含有IFrame并且IFrame指向child.html?,F(xiàn)在需要在parent.html/child.html中調用child.html/parent.html的一個js方法。   

具體的代碼實現(xiàn)如下:

parent.html父頁面:

復制代碼 代碼如下:
<html>
<head>
<script type="text/javascript">
  function parent_click(){
    alert("來自父頁面");
  }
</script>
</head>
<body>
  <input type="button" value="調用本頁面函數(shù)" onclick="parent_click();" />
  <input type="button" value="調用子頁面函數(shù)" 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("調用的子頁面函數(shù)");
  }
</script>
</head>
<body>
  <input type="button" value="調用父頁面函數(shù)" onclick='parent.window.parent_click();' />
  <input type="button" value="調用本頁面函數(shù)" onclick="child_click();" />
</body>
</html>

希望本文所述對大家基于javascript的web程序設計有所幫助。

相關文章

最新評論