项目作者: ondrejvrabel

项目描述 :
SingleTab prevents users from opening multiple tabs.
高级语言: JavaScript
项目地址: git://github.com/ondrejvrabel/singletab.git
创建时间: 2018-03-03T08:02:18Z
项目社区:https://github.com/ondrejvrabel/singletab

开源协议:MIT License

下载


SingleTab

SingleTab prevents users from opening multiple tabs in modern browsers.
If you need to prevent users from opening your page/web application in mutliple windows or tabs, this is solution for you.
Just include SsingleTab into footer of every page which cannot be opened mutliple times and when SingleTab fires your function, display alert or redirect user.

Known issues

  • SingleTab does not work in browsers without Local Storage support
  • SingleTab has some issues in Internet Explorer

    How to use SingleTab?

  1. Import it: <script src="singletab.js"></script>
  2. Initialize it: singleTab.init({ /* parameters */ });
  3. Start: singleTab.start();

    Parameters

  • interval - checking interval in miliseconds (default: 200)
  • storage - name of local storage (default: singletab-ls)
  • ignoreDate - if set to 0, “fire” is not fired on the first opened tab (default: 0)
  • fire - function to fire when multiple tabs detected (fires on every tab when ignoreDate is 1)
  • multifire - function to fire every time when “check” is called and detects page loaded in multiple tabs (warning: multifire fires approx. every interval ms when tabs are detected)

    Example

    View on htmlpreview.github.io

    1. <script>
    2. singleTab.init({
    3. fire: function() {
    4. document.getElementById('result').innerHTML='Hey! Close it!';
    5. },
    6. storage: "name",
    7. interval: 500
    8. });
    9. singleTab.start();
    10. </script>

    Warning

    This is just a quick project - code was not tested in older browsers and you shouldn’t rely on it. It might be better to implement some AJAX and Database solution. If user disables Javascript/uses older browser or IE, they can easily bypass SingleTab.