Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you communicate between two browser tabs/windows? [duplicate]

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.

like image 330
Justin Avatar asked Nov 12 '10 18:11

Justin


People also ask

How do I share data between two tabs?

Sending Data To send something to another tab, we need to first create a new BroadcastChannel instance. This is super easy, and looks like this: const channel = new BroadcastChannel("my-channel"); Notice how we passed in my-channel - this is the name of the channel which we are subscribing to.

What happens if two browser tabs go to the same Web server?

If you use many tabs to connect to the same remote server (or there are many users connecting to the server) they all go to the same port and are serviced by the same process (i.e. the web server of the site). This is the correct answer. TCP connections have a port number on both ends.

Can browser tabs communicate?

One of the traditional ways of communicating across Browser Tabs, Popups, and Iframes is Window. postMessage() method. You can send the message as follows. And the target window can listen to the events, as shown below.


1 Answers

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.

like image 70
Amir Raminfar Avatar answered Sep 28 '22 00:09

Amir Raminfar