Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference parent window document

I'm trying to access the parent window document from a popup.

<script type='text/javascript'>
    $(document).ready(function(){
        var summary = window.parent.document.getElementById('summary');
        var content = summary.innerHTML;
    });
</script>

Is it even possible? Is there a jQuery specific way to do it?

Thanks

like image 312
Lorenzo Avatar asked Mar 26 '09 16:03

Lorenzo


People also ask

What is the parent of a window in HTML?

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.

What is the parent of a window or subframe?

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.

How to share data between parent window and child window?

winobj=window.open (..) ... We can even have a function with arguments and use it as a workaround to share data between parent and child browser windows at some scenarios as shown below: window.opener.functioname (arg1,arg2,..)

How to access the child window elements of a window?

We can access the child window elements by using the window handle that will be returned by the window.open () method, as shown below: winobj=window.open (..) ... The winobj is actually a window object instance of the newly created window.


2 Answers

You want window.opener not window.parent (that's for frames).

like image 156
Greg Avatar answered Sep 23 '22 19:09

Greg


You can use context to accessed it:

<script type="text/javascript">
    $(document).ready(function(){
        var content = $("#summary",window.opener.document).html();
    });
</script>
like image 26
aprian Avatar answered Sep 24 '22 19:09

aprian