Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am facing cross domain issue with my application.

In have an application with url http://localhost:3334/myapp/mypage.aspx

Mypage.aspx has an Iframe.
Iframe's src is http://machine1/search/default.aspx

When I click a button in default.aspx, it should pass few values to the host application and host application should do some calculations on those values.

I added a javascript on the button click in default.aspx where it tries to access parent.top but I get the object but most of its properties show access denied.

is there any way I should pass the values from default.aspx and get in mypage.aspx?

Thanks

Vijay
Posted

So far as I know if the child page (Inside the IFRAME) and the parent page (That contains the IFRAME) are originated from the same domain, then only the child page can access the Document Object Model of the parent page and vice-versa.

On the other hand, if the child page and the parent page are originated from different domain, then, the child page cannot access the Document Object Model of the parent page. Also, the parent page cannot access the Document Object Model of child page.

However, I found a cool idea that utilizes the fact that, despite the parent and child pages are form different domain, they can access each other's URL (location.href). So, when the child want to do something on the parent page, it does as follows:

1. Child page modifies the location.href of the parent page by appending a fragment identifier (The hash part of the URl, such as, http://www.mysite.com/default.aspx#introduction, here #introduction is the fragment identifier). The fragment identifier that is to be set is usually the parameter value that the child page wants to send to the parent page.

2. The parent page continuously polls it's URL value at a certain time interval and whenever it detects a change in its URL value (location.href), it splits the fragment identifier value and updates its own DOM.

Using the same technique, the parent page also can trigger some change in the child page within an IFrame.

You can see a demo here : http://ajaxify.com/run/crossframe[^]
 
Share this answer
 
One way to solve those issues is to not load data from different domains. Using URL rewriting on the server can help you achieve that.

I have been using ISAPI Rewrite[^] to redirect calls to another server. There are probably heaps of other similar tools. URL rewriting works pretty well, and you don't have to rely on any hacks to make it work. The downside is that it is only suitable for certain types of applications.

In your case you could set it up locally, and make a specific path correspond to the IFRAME href.

E.g. on your local server, rewrite
http://localhost:3334/machine1/search/default.aspx
to
http://machine1/search/default.aspx

From your page, you can now get the remote page via your own domain.

I hope you get the idea.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900