Close Window from within External Content

8 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    57 posts
    Member since:
    Jun 2012

    Posted 09 Jul 2012 Link to this post

    I am creating a window as shown below:

    $("#wnd" + uniqueId).kendoWindow({
                           actions: ["Refresh", "Maximize", "Minimize", "Close"],
                           draggable: true,
                           height: Height + "px",
                           modal: false,
                           resizable: true,
                           title: Title,
                           width: Width + "px",
                           content: NavURL,
                           iframe: true
                       });

    But how can I close this window from a button on the content that is on the NavURL?
  2. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 10 Jul 2012 Link to this post

    Hi Jonathan,

    The Window object can be accessed from its content in two ways, depending on whether the content resides in an iframe or not.

    1. If an iframe is used, then you can reach the Window client object only if the iframe URL is on the same domain as the main page. In this case use the window.parent property, which gives you a reference to the main / parent page.

    window.parent.$("#window-ID").data("kendoWindow").close();


    2. If an iframe is not used, you can reach the Window by using the closest() jQuery method...

    $( buttonInsideWindow ).closest(".k-window-content").data("kendoWindow").close();

    ... or by referencing the element with the window ID directly, similarly to the first case, but without window.parent.


    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!
  3. Kendo UI is VS 2017 Ready
  4. Ravisankar
    Ravisankar avatar
    2 posts
    Member since:
    Jan 2012

    Posted 02 Aug 2012 Link to this post

    I have a main page that has button. On clicking the button a window opens which has another html as its content. In the child window i have a button clicking on which the window should close. I tried your example and couldnt get it working.

     <script>
             $(document).ready(function () {
     
                 $("#btnCancel").closest(".k-window-content").data("kendoWindow").close();
     
             });
                </script>

    btnCancel is the button id.
    Please let me know what i am doing wrong.
  5. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 03 Aug 2012 Link to this post

    Hi Ravisankar,

    I don't see how the provided code is related to a button click. Please explain in more detail.

    The provided code as is may not be executed correctly, because the Window client object may still not be initialized.

    Greetings,
    Dimo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Ron DeFreitas
    Ron DeFreitas avatar
    26 posts
    Member since:
    Apr 2010

    Posted 04 Dec 2012 Link to this post

    Ravisankar, you need to bind the click event handler for your button:
    $(document).ready(function () {
        $("#btnCancel").live("click", function (e) {
            if ($(this).closest(".k-window-content").data("kendoWindow")) $(this).closest(".k-window-content").data("kendoWindow").close();
        })
    });
    The code sample also takes into account whether or not the window has been initialized.

    Optionally you can add e.preventDefault() if you want to stop the click event's normal behavior.
  7. John
    John avatar
    25 posts
    Member since:
    Mar 2007

    Posted 13 Dec 2012 Link to this post

    Just resurrecting this.

    If I try this, when I click the close button in my window I get the following error:

    Unable to get value of the property 'close': object is null or undefined
  8. John
    John avatar
    25 posts
    Member since:
    Mar 2007

    Posted 13 Dec 2012 Link to this post

    OK, I fixed it!
  9. Flavio Lepka
    Flavio Lepka avatar
    8 posts
    Member since:
    Mar 2006

    Posted 01 Jul 2013 Link to this post

    tks
Back to Top
Kendo UI is VS 2017 Ready