tags:

views:

47

answers:

1

Hi guys:

The following JS will fail if the URL in mainFrame from a.abc.com to b.abc.com.

top.frames["mainFrame"].location.href = "/Users/xuenn.aspx?backUrl=" + top.frames["mainFrame"].location.href.split("?")[0];

This is the error message: Permission denied for http://a.abc.com to get property Location.href from http://b.abc.com.

Anybody knows how could I workaround this or think of other solutions?

A: 

Access to [window]s from other domains are prohibited by the Same Origin Policy, the location property is however writable.

In this case, you need to either use document.domain = foo, or in some other way pass the expected url to a.abc.com, for instance using #http://b.abc.com/ or ?b=http://b.abc.com/ so that you don't need to read the property.

In the first case, note that this might create problems with scripts that use iframes to post/upload data to the server asynchronously as these will no longer have access to the iframes content after setting document.domain.

If your environment is cross-domain then you should probably look into easyXDM as well. This is a easy-to-use library that lets you communicate across domain boundaries, event with RPC calls. You can try one of the examples here, this enables cross-domain XHR.
Read more about the example at http://easyxdm.net/wp/2010/03/17/cross-domain-ajax/

Sean Kinsey