最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cross domain popup window with return value - Stack Overflow

programmeradmin2浏览0评论

This is the setup:

I have two websites on two different domains:

  • www.website1
  • www.someotherwebsite

This is what I want to do:

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

  2. When the user clicks a button in the popup window (showing www.someotherwebsite) 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.

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.

This is the setup:

I have two websites on two different domains:

  • www.website1.
  • www.someotherwebsite.

This is what I want to do:

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

  2. When the user clicks a button in the popup window (showing www.someotherwebsite.) 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..

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.

Share Improve this question asked Sep 18, 2009 at 8:03 user5722user5722 1,2943 gold badges10 silver badges13 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

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.

You could post the value in the popup from www.someotherwebsite. back to a special page on www.website1.. 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.

发布评论

评论列表(0)

  1. 暂无评论