简体   繁体   English

如何在父窗口中从其调用方获取iFrame的引用

[英]How to get reference of iFrame from its caller in parent window

I have javascript module like below in my main page. 我的主页上有如下所示的javascript模块。

var LX = (function () {
    this.print_msg(divID){
        document.getElementById(divID).innerHTML = "some computed message";
        //above line throw error : TypeError: document.getElementById(...) is null
    }
    // some others functions
    retrun this;

})(); 

There are many iframes dynamically created in this page. 此页面中动态创建了许多iframe code in all iFrame as below 所有iFrame中的代码如下

<div id="msgDiv"></div>
<script>
LX = parent.LX ;
LX.print_msg("msgDiv");
</script>

my problem is How to get reference of iFrame from its caller in parent window ?? 我的问题是如何从父窗口的调用方获取iFrame的引用?

If the msgDiv is in the iframe, you need to pass window too. 如果msgDiv在iframe中,则也需要传递窗口。 For example LX.print_msg(window,"msgDiv"); 例如LX.print_msg(window,"msgDiv"); and use 和使用

this.print_msg(win,divID){ win.document.getElementById(divID).innerHTML = "some computed message";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM