Prevent Webpage From Being Opened In Multiple Tabs - duplicateWindow

File Size: 15.6 KB
Views Total: 19941
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Prevent Webpage From Being Opened In Multiple Tabs - duplicateWindow

duplicateWindow is a small jQuery plugin that checks if the current window is duplicate window to prevent your webpage from being opened in multiple browser tabs.

Based on the HTML5 local storage and session storage. Inspired by the answer from 'Stop people having my website loaded on multiple tabs'.

How to use it:

1. Download the plugin and include the JavaScript file Duplicate.js after you've loaded the latest 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. Check if the current window is duplicate window and auto close the tab with an alert popup box.

$(document).ready(function () {
  if (window.IsDuplicate()) {
    alert("This is duplicate window\n\n Closing...");
    window.close();
  }
});

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