1

I like to prevent the user from opening my webpage in more then one window/tab.

I tried naming the window with window.name but you end up with two windows with the same name.

PS: I use pure/vanilla Javascript

Alessandro
  • 900
  • 12
  • 23
RoboTamer
  • 3,474
  • 2
  • 39
  • 43
  • 2
    It will be hard to prevent the user to open the same page twice. Since a web page does not know the other pages open in a browser – David Laberge Mar 18 '15 at 15:23
  • 1
    Make a login, and if they open the same page again, check if logged in, and show them something like "You're already logged in stahp" – Sterling Archer Mar 18 '15 at 15:25
  • Maybe you could use cookies – Hacketo Mar 18 '15 at 15:27
  • 1
    And what happens if the user opens 2 or 3 different webbrowsers or with different devices? you can't control it with pure javascript. Use something like persistent websokets and check if the user is already connectet to that websocket or not. – nada Mar 18 '15 at 15:35
  • It seems that there is already an answer that works for this question: http://stackoverflow.com/questions/19313017/detect-if-two-browser-windows-are-open-to-the-same-site – KJ Price Mar 18 '15 at 15:39

1 Answers1

1

One option here is to track what pages you (your script) specifically opened and store that in local storage. Since local storage is shared between tabs/windows, you could keep track of open windows. The limitation to this is if that window was opened by other means, it could be a bit problematic.

nick
  • 610
  • 5
  • 12