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

Close Window from content?

3 Answers 351 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 11 May 2012, 11:40 AM
Hello,

I would like to know if window content can close the window?

Here's my code so far:
<div id="myWindow">
    <button onclick="CloseWindow()" >Close Me</button>
 
    <script type=text/javascript>
 
        function CloseWindow() {
 
            try {
                var kendoWindow = $("#myWindow").data("kendoWindow").close();
            }
            catch (err) {
                //Unable to get value of the property 'close': object is null or undefined
                alert("Error \n\n" + err.message);
            }
                                 
        }
      
    </script>
</div>
 
<script>
    $(document).ready(function () {
 
        var myWindow = $("#myWindow").kendoWindow({
            width: "300px",
            height: "200px",
            title: "Login",
            modal: false
        });
 
    });
</script>


Unfortonately, the following error is raised when trying to close the window:
Unable to get value of the property 'close': object is null or undefined

I would also like to know if there is a solution that would also work with external content?
Ex:
var myWindow = $("#myWindow").kendoWindow({
    width: "300px",
    height: "200px",
    title: "Login",
    modal: false,
    content: "myExternalContent.aspx"
});

... where myExternalContent.aspx would be able to access myWindow and close it even if it's not in the same page.

Best regards,

Simon


3 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 11 May 2012, 12:26 PM
Hello Simon,

Closing the Window from its content is possible and there are two distinct scenarios.

1. The Window uses an iframe to display another page (your case).
2. The Window does not use an iframe and displays random HTML markup.

The second case is trivial. You don't need to hard-code any IDs, just use

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

The first case has one major limitation that you should be aware of, namely, the page in the Window iframe must be in the same domain. Only in this case you will be able to access the parent document from within the nested page (via window.parent), obtain a reference to the Window object and call its close() method.

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!
0
Simon
Top achievements
Rank 1
answered on 11 May 2012, 12:42 PM
Hello Dimo,

Thanks for your help.

By any chances, do you have any code snipped for the first example (Window.Parent)?

Simon
0
Dennis
Top achievements
Rank 1
answered on 26 Aug 2012, 12:29 PM
Hi I'm trying to achive this also, I'm not using an iframe but this does not work for me:

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

javascript gives out an error that it doesnt recognize buttonJQueryObject. Right now I'm doing this by hardcoding a reference to the Window ID. This is def not a good solution for me as my app is gonna have lots of these windows once it grows, and hardcoding IDs like this is gonna turn into maintance nightmare.
Tags
Window
Asked by
Simon
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Simon
Top achievements
Rank 1
Dennis
Top achievements
Rank 1
Share this question
or