views:

813

answers:

2

This is the setup:

I have two websites on two different domains:

  • www.website1.com
  • www.someotherwebsite.com

This is what I want to do:

  1. When a user is on www.website1.com and clicks a link, I want a window to popup showing www.someotherwebsite.com.

  2. When the user clicks a button in the popup window (showing www.someotherwebsite.com) I want that window to close and have a value returned.

  3. I want the value returned from the popup window to be placed (into a div, or into a javascript call, or someplace accessible such as filling out a form field) on www.website1.com.

I hope that makes sense. I need to use just HTML and Javascript without external libraries. It also must work on current mainstream browsers (i.e. not be an HTML5 thing).

Thank you in advance for your help.

+2  A: 

Well if you use an iframe in your pop up window [in this day in age I would avoid pop up windows like the plague due to pop up blockers]

With an iframe you can make cross domain calls

Why don't you just develop a webservice from A to B and call it from A? Seems so much cleaner than finding small cracks in browsers to get around security.

epascarello
+1 for proxy web service recommendation. Seems to fit nicely, unless B requires a bunch of interactivity from the user.
Josh Stodola
Thanks! This pointed me in the right direction.What I eventually did was:1) website A creates an iframe pointing to website B www.b.com/iframe2) Website B in iFrame pops up a window also on Website B www.b.com/control3) Control does whatever processing it wants. When the user clicks the close button Javascript is used to push the result back into the www.b.com/iframe page4) www.b.com/iframe modifies the hash of the parent page to pass the result back there5) parent page does what it will with the result
References:http://softwareas.com/cross-domain-communication-with-iframeshttp://ajaxpatterns.org/Unique_URLshttp://chiragrdarji.wordpress.com/2007/03/10/call-parent-windows-javascript-function-from-child-window-or-passing-data-from-child-window-to-parent-window-in-javascript/
+2  A: 

You could post the value in the popup from www.someotherwebsite.com back to a special page on www.website1.com. Now you're back into the original domain, that page takes the GET value and writes it out into some JavaScript. The JavaScript then updates the value somewhere in the opener window use opener.document.getElementById, or calls a function in the opener with something like opener.document.doSomething(val); which handles the response.

It's fraught with potential errors (what if the user opens two copies of the window? Or closes the original site?) and potential security holes, and browsers have a tendency to react badly if you try to do things to windows that don't exist or are in different domains, but in a known environment it should work.

Karl B