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

Cross Domain - Closing Window

6 Answers 153 Views
Window
This is a migrated thread and some comments may be shown as answers.
SomeName
Top achievements
Rank 1
SomeName asked on 11 Jul 2011, 12:44 PM
I'd like to close the opend window i called in a cross domain site.
So, when the user hits the "Close" button on the child page (different domain) the radwindow shall close.

This is easily possible with normal popup windows, just use the javascript code. window.close();
In Demos you can find an example for Dialog returning values and there is a javascript method to find the radwindow and than call the close event, but this doesnt work in cross domain scenarios.

Example from Demos
function GetRadWindow() {
 
var oWindow = null;
 if (window.radWindow)
oWindow = window.radWindow;
 
//Throws an Error in cross domain, because window.frameElement isnt accessible
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
 
return oWindow;
 
 }


To Close just say...
var oWnd = GetRadWindow();
oWnd.close(oArg);


Hope you guys can help me close a radwindow in cross domain scenario.

6 Answers, 1 is accepted

Sort by
0
SomeName
Top achievements
Rank 1
answered on 19 Jul 2011, 06:41 AM
Does anyone have an idea how to solve this problem?
0
Marin Bratanov
Telerik team
answered on 20 Jul 2011, 01:33 PM
Hello,

Please note one main difference between a browser window and a RadWindow - the RadWIndow is actually a server control (i.e. a collection of HTML elements, JavaScript and CSS) that resides in the page. It cannot exist outside of the page lifecycle, while the browser is a standalone application in the user's machine.

This means that you can interact with the RadWindow only via JavaSctipt in the context of its own page and JavaScript does not allow access from a different domain. Please examine the following google search for more information on this limitation: http://www.google.com/search?&q=javascript+crossdomain+policy.

In conclusion - you can manipulate the RadWindow object only if you have access to the page that contains it. If you can do it from a different domain then oWnd.close() should work for you, but this would be hacking the other person's page and I doubt that it can be achieved.


All the best,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
SomeName
Top achievements
Rank 1
answered on 20 Jul 2011, 05:46 PM
Thanks for the answer. FYI, both domains are mine.
I just need a to call a radwinow and there an aspx page, because of limitations that arent in my hand, i cannot run code on one server because it only works on the local machine.

So what i have done is, from my webserver (1st domain) i call one single page on 2nd domain and do somestuff in the aspx page (that as metioned only works on local machine).
When hitting the "Done/Close" Button i want to automatically close the RadWindow.

Since you said first its not possible, but then mentioned about hacking it can be achieved.. I am not sure now, what the case is...

So if its possible since both domains belong to me please tell me how to achieve it. Thanks in advance.
0
Marin Bratanov
Telerik team
answered on 21 Jul 2011, 12:04 PM
Hello again,

Please excuse me for not being clear enough in my previous post. It does not matter who owns the domains, JavaScript will not allow you to access pages from different domains regardless of their physical owner. What I meant under hacking is exactly this - probably somewhere a hack/hacker exists that is capable of accessing another domain, but I cannot be certain of this. As far as we know there is no way to access a different domain via JavaScript, thus you couldn't close the RadWIndow from within if the page comes from another domain. The closest thing to a hack there is is changing the domain of the document object so that it uses only the last part of the domain, for example site1.mydomain.com and site2.mydomain.com could be made to look like mydomain.com and could be accessible under certain conditions. For more information on this approach please examine the following google search: http://www.google.com/search?q=cross+domain+javascript.


Greetings,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Greg
Top achievements
Rank 1
answered on 14 Mar 2012, 11:12 PM
I understand the restriction for cross domain close, but how is it your X (close) button works on the Radwindow itself?  Is there anyway to emulate the functionality of the X button like a regular button on the page?
0
Kevin
Top achievements
Rank 2
answered on 15 Mar 2012, 01:13 PM
Hello Greg,

The reason you can close a RadWindow manually using the X (close) button is because that button is not conatined inside the iFrame of the RadWindow, which is referencing the external site, thus the X (close) button can access the RadWindow object. When an external page is displayed in the RadWindow and is not within the same domain as the page containing the RadWindow, the GetRadWindow() method cannot gain access the parent page that the iFrame is contained in because of security concerns and thus the reason it cannot access the RadWindow object and call the close method.

I hope that makes sense.
Tags
Window
Asked by
SomeName
Top achievements
Rank 1
Answers by
SomeName
Top achievements
Rank 1
Marin Bratanov
Telerik team
Greg
Top achievements
Rank 1
Kevin
Top achievements
Rank 2
Share this question
or