This is a migrated thread and some comments may be shown as answers.

When using iframe, how to get instance of self window?

6 Answers 738 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 16 Feb 2012, 06:54 PM
Open a window using an iframe.  

How, using jQuery, would you get a reference to the window (from within the window) so you can close it?

6 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 17 Feb 2012, 12:41 PM
Hi Jeremy,

http://www.google.com/search?q=get+parent+window+from+iframe

Once you have the reference to the parent page, the logic is the same is if you are in the current page.

parent.$("#WindowID").data("kendoWindow").close();

Note that this will work only if the iframe and the main page are in the same domain.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Courouble Damien
Top achievements
Rank 1
answered on 27 Apr 2012, 03:58 PM
Hi guys, 

I'm doing same stuff as you did, working with an iframe inside a window.
I'm trying to change the title of it when document ready of child page is reached.

But for some reason the .data("kendoWindow") is undefined.

here's my instanciation

function DisplayWindow(pSrc, pWidth, pHeight, pResizable, pModal) {

    // Defaults
    pWidth = typeof (pWidth) != 'undefined' ? pWidth : 525;
    pHeight = typeof (pHeight) != 'undefined' ? pHeight : 450;
    pResizable = typeof (pResizable) != 'undefined' ? pResizable : false;
    pModal = typeof (pModal) != 'undefined' ? pModal : true;

    var tWindow = null;

    // Setup dialog objects
    var tDOMWindow = $('<div id="DialogWindowContainer" style="overflow: hidden;"></div>');
    tWindow = tDOMWindow.kendoWindow({
        actions: ["Close"],
        draggable: false,
        height: pHeight,
        width: pWidth,
        modal: pModal,
        content : pSrc,
        resizable: pResizable,
        visible: false
    }).data("kendoWindow");

    tWindow.center();
    tWindow.open();
    return false;
}

Accessing  $("#DialogWindowContainer") or parent.$("#DialogWindowContainer") from the child page return object but parent.$("#DialogWindowContainer").data("kendoWindow") or $("#DialogWindowContainer").data("kendoWindow") return undefined so I can't call the .title() method.

I don't get it, am I doing something wrong ? I've also try to put iframe:true, and test a couple of others things but without success

Thanks,

Damien
0
Ambica
Top achievements
Rank 1
answered on 08 May 2012, 08:56 AM
Remove jquery.min.js  reference from  child page . 
0
Simon
Top achievements
Rank 1
answered on 11 May 2012, 02:57 PM
Same problem as Damien here...

Removing this line didn't fix the problem:
<script src="/js/jquery.min.js" type="text/javascript"></script>


0
Dimo
Telerik team
answered on 11 May 2012, 03:31 PM
Hello Simon,

Please open a new support ticket and attach a runnable demo, so that I can check it locally and help you further.

Kind regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nathan
Top achievements
Rank 1
answered on 27 Dec 2012, 09:55 PM
It's important that you do it exactly like Dimo demonstrated

parent.$("#WindowID").data("kendoWindow").close();
Note that he is calling '$' as a property of 'parent'. This ensures that you will be using the parent window's instance of jQuery and not the iframe's instance. If you use the iframe's instance of jQuery, the data() function on your element will not return the data you are expecting because it doesn't exist in the scope of the iframe's instance of jQuery.

I hope this helps anyone who is confused.
Tags
Window
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Courouble Damien
Top achievements
Rank 1
Ambica
Top achievements
Rank 1
Simon
Top achievements
Rank 1
Nathan
Top achievements
Rank 1
Share this question
or