最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Access parent object in JavaScript from iFrameWindow - Stack Overflow

programmeradmin3浏览0评论

How do I access a global object or array defined in a parent window in the child window.

<script>
    var events_data;
    function function_to_fill_events_data () {
      .
      .
      .
    }
</script>

<div>
    <div><iframe src="mini.php" width:100%; height: 100%;" scrolling="no"></iframe> </div>
</div>

When I am in the mini document I'd like to be able to access the events_data variable in a javascript function.

How do I access a global object or array defined in a parent window in the child window.

<script>
    var events_data;
    function function_to_fill_events_data () {
      .
      .
      .
    }
</script>

<div>
    <div><iframe src="mini.php" width:100%; height: 100%;" scrolling="no"></iframe> </div>
</div>

When I am in the mini document I'd like to be able to access the events_data variable in a javascript function.

Share Improve this question edited Mar 19, 2012 at 16:57 James Hill 61.8k22 gold badges149 silver badges166 bronze badges asked Mar 19, 2012 at 16:48 user823527user823527 3,71217 gold badges69 silver badges111 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

Option 1

Your title mentions a child window. If you have a child window, and not an iframe, use this:

window.opener.events_data

Check out window.opener on MDN.

Option 2

Your code indicates that you're using an iframe. From an iframe, simply use parent:

parent.events_data;

Check out window.parent on MDN.


window.opener - Returns a reference to the window that opened this current window.

window.parent - When a window is loaded in an , , or , its parent is the window with the element embedding the window.

发布评论

评论列表(0)

  1. 暂无评论