views:

413

answers:

5

Here's my problem - I'd like to communicate between two websites and I'm looking for a clean solution. The current solution uses Javascript but there are nasty workarounds because of (understandable) cross-site scripting restrictions.

At the moment, website A opens a modal window containing website B using a jQuery plug-in called jqModal. Website B does some work and returns some results to website A. To return that information we have to workaround cross-site scripting restrictions - website B creates an iframe that refers to a page on website A and includes fragment identifiers containing the information to be returned. The iframe is polled by website A to detect the returned information. It's a common technique but it's hacky.

There are variations such as CrossSite and I could perhaps use an HTTP POST from website B to website A but I'm trying to avoid page refreshes.

Does anyone have any alternatives?

EDIT: I'd like to avoid having to save state on website B

+2  A: 

With jQuery newer than 1.2 you can use JSONP

Pat
+4  A: 

My best suggestion would be to create a webservice on each site that the other could call with the information that needs to get passed. If security is necessary, it's easy to add an SSL-like authentication scheme (or actual SSL even, if you like) to this system to ensure that only the two servers are able to talk to their respective web services.

This would let you avoid the hackiness that's inherent in any scheme that involves one site opening windows on the other.

DannySmurf
A: 

@Pat - that's a solution I hadn't seen, thanks

@jmein - can you elaborate?

Robin M
A: 

@jmein - you've described how to create a modal popup (which is exactly what jqModal does) however you've missed that the content of the modal window is served from another domain. The two domains involved belong to two separate companies so can't be combined in the way you describe.

Robin M
A: 

i believe @pat was refering to this

"As of jQuery 1.2, you can load JSON data located on another domain if you specify a JSONP callback, " http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback

vitorsilva