9

I have a web application that launches as second web application in a new browser window / tab. I want to update the content on the original page when the user submits their input on the second page.

Real World Example:

Google uses this behavior in Gmail. When composing a new message, if you click the "To" link, it brings up a list of your contacts in a new browser window. This leaves the original compose email window open and active for input while the user can at any time select the email recipients from the list of contacts. When they submit that window, the selected email addresses are added to the recipient list in the original compose window.

How is this accomplished? I imagine it could be done using Ajax, but ideally the solution will avoid the round trip / programming logic required to route it via the server.

For reference, my technology stack for this is an ASP.NET MVC application launching a second ASP.NET MVC application that contains a Silverlight application. Both applications can / do make use of jQuery.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Justin
  • 10,667
  • 15
  • 58
  • 79

2 Answers2

12

I don't think you mean two tabs. What Gmail is doing is communicating between a pop up and the parent.

So let's say you opened a new window using JavaScript. In the opened window you can do:

opener.someFunction() to pass data back. Let me find a solid example and paste it.

Here is a good example. http://www.javascriptkit.com/javatutors/remote2.shtml

You can use the opener to do a lot.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amir Raminfar
  • 33,777
  • 7
  • 93
  • 123
  • This looks like what I want to use. I tried the simple tests in your link. Works perfect for Firefox and IE but fails in Chrome. The parent window's colour is never updated. Any idea why? – Justin Nov 12 '10 at 19:35
  • @Amir: you may want to paste the example here, maybe in a code snippet, in case the JavaScriptKit website goes down. – Dan Dascalescu Jul 11 '15 at 02:46
  • Would this solution be able to leverage the same session in an authenticated website? – Chris SH Aug 11 '15 at 16:01
  • 1
    this approach is not working with IE (10, 11 and Edge atleast). I want to send the selected file from child to opener. I have asked a question here: http://stackoverflow.com/q/43681241/1660192 – Aman Gupta May 01 '17 at 08:27
-2

You have two possibilities:

  1. Constant polling (setInterval and AJAX)
  2. Push (Comet and HTML 5 WebSocket API)
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928