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

javascript - Access DOM objects of parent window from jQuery DOMWindow loaded with iFrame - Stack Overflow

programmeradmin4浏览0评论

I have a web-page with a jQuery DOMWindow that loads its content from an iFrame. I need to access elements of the parent window from the iFrame. Is this possible?

This is the configuration for the DOMWindow that is opened from my main page:

        <script type="text/javascript">
            $('.AjaxDOMWindow').openDOMWindow({
                anchoredClassName:'DOMWindow',
                draggable: 1,
                eventType:'click',
                height:500,
                loader:1,
                loaderHeight:16,
                loaderImagePath:'/js/jquery/DOMWindow/animationProcessing.gif',
                loaderWidth:17,
                positionLeft:0,
                positionTop:0,
                positionType:'centered',
                width:700,
                windowSource:'iframe'
            });

I'm attempting to access the parent window's elements from the DOM box with:

parent.document.getElementById('foo').innerHTML = '';

But this doesn't appear to work. Thanks!

I have a web-page with a jQuery DOMWindow that loads its content from an iFrame. I need to access elements of the parent window from the iFrame. Is this possible?

This is the configuration for the DOMWindow that is opened from my main page:

        <script type="text/javascript">
            $('.AjaxDOMWindow').openDOMWindow({
                anchoredClassName:'DOMWindow',
                draggable: 1,
                eventType:'click',
                height:500,
                loader:1,
                loaderHeight:16,
                loaderImagePath:'/js/jquery/DOMWindow/animationProcessing.gif',
                loaderWidth:17,
                positionLeft:0,
                positionTop:0,
                positionType:'centered',
                width:700,
                windowSource:'iframe'
            });

I'm attempting to access the parent window's elements from the DOM box with:

parent.document.getElementById('foo').innerHTML = '';

But this doesn't appear to work. Thanks!

Share Improve this question asked Jan 31, 2011 at 19:28 Casey FlynnCasey Flynn 14k26 gold badges108 silver badges196 bronze badges 2
  • Possible duplicate of stackoverflow./questions/726816/… – Lance Commented Jan 31, 2011 at 19:31
  • Not sure if this is a duplicate. Thank you for the suggestion. The above question doesn't refer to an iframe loaded inside of a DOMWindow - which is my scenario. – Casey Flynn Commented Jan 31, 2011 at 19:33
Add a ment  | 

3 Answers 3

Reset to default 8

Change

parent.document.getElementById('foo').innerHTML = '';

to

window.parent.document.getElementById('foo').innerHTML = '';

I see you have jquery as tag so you can do this as below.

$( "#foo", window.opener.document)

OR

window.opener.document.$("#foo")

This could also work :

$(window.parent.document).find("#foo")
发布评论

评论列表(0)

  1. 暂无评论