Skip to content

Instantly share code, notes, and snippets.

@manikantag
Created September 27, 2023 14:36
Show Gist options
  • Save manikantag/273a57e1ab011515a07c4a5dbd3677fc to your computer and use it in GitHub Desktop.
Save manikantag/273a57e1ab011515a07c4a5dbd3677fc to your computer and use it in GitHub Desktop.

Revisions

  1. manikantag created this gist Sep 27, 2023.
    16 changes: 16 additions & 0 deletions duplicate-tab-check.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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';
    }