Need to change the Parent URL of nested Windows

4.4k Views Asked by At

I currently have a form that is being iFramed into an application that acts as a search bar. When users hit enter in this search, the form redirects the parent window to a different URL within the application. Note that these have the same domain, but different sub-domains. This part works well. See the code below.

window.parent.location = redirectUrl;

The issue is that I have a customer who is iFraming this application into another application. When they go to perform this search in this scenario, we are getting an error that says that "the frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener."

Is there a workaround around for getting this to work?

2

There are 2 best solutions below

0
On

The browsers would typically disallow that if the domain is different.

You might be able to set response headers to tell the browser to allow the request to go through:

Access-Control-Allow-Origin: http://example.com

See below: http://www.staticapps.org/articles/cross-domain-requests-with-cors

0
On

You're accessing the window object which, being on a different domain, is restricted by cross origin policy.

You could look at accessing the parent document directly, going up from the active frame, rather than going down from the top (window)

Example of the window and document objects

Credit for the image and decent reference

http://eligeske.com/jquery/what-is-the-difference-between-document-and-window-objects-2/