Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access DOM objects of parent window from jQuery DOMWindow loaded with iFrame

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!

like image 460
Casey Flynn Avatar asked Jan 31 '11 19:01

Casey Flynn


People also ask

Can iframe access parent windows?

The window will get opened by using the iframe, and the communication could be done with the parent window from the child window. To call a parent window function, use the following syntax and also refer to the code given below.

What is the parent window?

The Window. parent property is a reference to the parent of the current window or subframe. If a window does not have a parent, its parent property is a reference to itself. When a window is loaded in an <iframe> , <object> , or <frame> , its parent is the window with the element embedding the window.


1 Answers

Change

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

to

window.parent.document.getElementById('foo').innerHTML = '';
like image 63
Lance Avatar answered Sep 18 '22 06:09

Lance