3

How can prepare a communication channel to communicate between multiple opened tabs in same browser without any server side support?

Hyd Gem
  • 43
  • 3

2 Answers2

4

Take a look at Window/postMessage.

You can also use Window.localStorage and register a StorageEvent and react on it from another tab.
Here's an interesting read: Using the Web Storage API;

EXAMPLE using localStorage and the StorageEvent

Put this into page1.html

<button>CLICK ME TO CHANGE "A" - "B"</button>
<script>
document.querySelector("button").addEventListener("click", function(){
  localStorage.ab = localStorage.ab ===  "A" ? "B" : "A";
});
</script>

and this into page2.html

<script>
window.addEventListener("storage", function( StorageEvent ){
  console.log( StorageEvent );
  alert(StorageEvent.newValue);
});
</script>
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
1

You can also leverage Web-Sockets to achieve real-time event based commincation across tab's and browsers. Libraries such as Socket.io make the entire process very straightforward.

AP.
  • 8,082
  • 2
  • 24
  • 33