Check Duplicate Browser Tabs/Windows With jQuery - duplicate.js

Check Duplicate Browser Tabs/Windows With jQuery - duplicate.js
File Size: 3.16 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

duplicate.js is a tiny, useful, jQuery based duplicate window checker that checks if a browser tab/window is already opened using pure JavaScript.

How to use it:

1. Download and put the JavaScript file duplicate.js after loading jQuery JavaScript library.

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" 
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
        crossorigin="anonymous">
</script>
<script src="duplicate.js"></script>

2. Do something if the current browser tab/window is duplicate.

$(document).ready(function () {

  if (window.IsDuplicate()) {

    // alert user the tab is duplicate
    alert("Window Already Opened in Another Tab\nPlease Click Ok");

    // close the current tab
    window.close();

  }
  
});

This awesome jQuery plugin is developed by AshrafAliS. For more Advanced Usages, please check the demo page or visit the official website.