Skip to content

Instantly share code, notes, and snippets.

@manikantag
Created September 27, 2023 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manikantag/273a57e1ab011515a07c4a5dbd3677fc to your computer and use it in GitHub Desktop.
Save manikantag/273a57e1ab011515a07c4a5dbd3677fc to your computer and use it in GitHub Desktop.
duplicate-tab-check.js
const tabCheckBroadcast = new BroadcastChannel("TAB_CHECK");
tabCheckBroadcast.postMessage("FIRST_TAB");
tabCheckBroadcast.onmessage = (event) => {
if (event.data === "FIRST_TAB") {
tabCheckBroadcast.postMessage("FIRST_TAB_OPENED");
}
if (event.data === `FIRST_TAB_OPENED`) {
alert("You are not supposed to duplicate the tab");
//disableApp();
}
};
function disableApp() {
document.body.classList.add("disable");
document.getElementById('maskApp').style.display = 'block';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment