js中iframe調用父頁面的方法,jsiframe調用頁面

來源:互聯網
上載者:User

js中iframe調用父頁面的方法,jsiframe調用頁面

本文執行個體講述了js中iframe調用父頁面的方法。分享給大家供大家參考。具體實現方法如下:

子頁面調用父頁面的方法在js中很容易實現。我們只需要在首頁面加個函數,然後在子頁面通過window.parent.方法()即可實現了

比如調用a()函數,就寫成:

複製代碼 代碼如下:window.parent.a();
但是我在chrome瀏覽器下卻發現此方法無效了

複製代碼 代碼如下://在父頁面中調用該函數

<script>
function dey() {
var cards_frame=document.frames("card-iframe");    //card-iframe為iframe的名字      
cards_frame.checkedCard()             //調用iframe中定義的方法,把內嵌頁面的值傳到父頁面
}
</script>
2)在iframe 中調用 父頁面定義的方法

複製代碼 代碼如下:function alert_window(picurl,h_id)
{
document.parentWindow.parent.msg(picurl,h_id);
}
//msg()為父視窗定義的函數.
card-iframe是iframe架構的id,b()為子頁面js函數。contentWindow屬性是指定的frame或者iframe所在的window對象,IE下可以省略。

希望本文所述對大家的javascript程式設計有所協助。


父視窗怎擷取子視窗的IFrame中的JS方法

給iframe設定上ID
document.getElementById('iframeid').contentWindow.abc();
abc() 為子頁面函數
 
js 父頁面不可以調用iframe頁面的方法為何?

如果iframe不是跨域訪問,那麼js可以父頁面調用子頁面中js的函數
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.