How can prepare a communication channel to communicate between multiple opened tabs in same browser without any server side support?
Asked
Active
Viewed 85 times
2 Answers
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