Created
January 8, 2024 07:49
-
-
Save Kcko/63cf68978e6720a85866b99471200887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Document</title> | |
</head> | |
<body> | |
<button>CLICK ME</button> | |
<script> | |
const channel = new BroadcastChannel('myChannel'); | |
document.getElementsByTagName('button')[0].addEventListener('click', e => { | |
channel.postMessage('Hello from Tab 1' + new Date().getSeconds); | |
console.log('CHANNEL 1'); | |
}); | |
channel.onmessage = event => { | |
console.log('Message received in Tab 2:', event.data); | |
console.log('CHANNEL 2'); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment