How do I avoid opening two browser windows?

I would like to avoid being able to open two application windows (or tabs). This is if my app (LAMP + Javascript) is installed on http://www.domain.com and the user is viewing the page http://www.domain.com/user/ he cannot open another window like http: / /www.domain.com/system/. If it opens another window, the application should show an error message.

Is it possible?

For curious people . I need this behavior because my application uses some session data to determine the sequence of actions. If the user opens a new window in one browser, everything is usually correct, but if he / she starts a new sequence, the previous one (in another window) will be lost.

+2


source to share


5 answers


While it is correct that everyone else here said that you cannot prevent someone from opening your site twice, there might be a workaround for you. Please note that this is not a 100% solution and will require you to code based on this.

From what I understand you have the following problems:

  • How to detect if a user opens your page with a window / tag that shares the session data (i.e. two tabs in Chrome, 2 Chrome windows, etc.) is the simplest part.
  • How to determine if a user opens your page in another browser (i.e. open in FF and Chrome in one go) is a tricky task.

However, you can use LSOs ​​- Local Shared Objects for this . These are flash cookies, similar to data stored on the client side. AND THEY ARE CROSS BROWSER AND PERFECTLY COMPATIBLE. You can find a nice library called EVERCOOKIE to use here .



By setting such a cookie, you will be able to track the user even if they open a new window or even if they open your page in a different browser, since the browsers use the same Flash installation, etc.

Note that this will not prevent someone from opening two windows directly, but you can send it to the same sequence state, for example in a different window.

You should also be aware that this is not a 100% solution. There will always be some trick to get around this, although I think regular users won't be able to get it ...

+2


source


You can not prevent anyone from opening your site twice.



You could use a new session key for each page, but that might make it a little thinner ...

+2


source


As mentioned above - you cannot prevent someone from opening your site twice. However, as I see it, your problem is to make sure each browser session is unique. There are many approaches to achieve this, one could generate a random number by the client and send it via ajax to the backend to be used instead of the session id, you might have some persistence issues, but these are easy solutions.

+2


source


The only way I can do this is to hide / remove the content if the user has gone elsewhere

So you have to: a) require the user to log in ... and b) records when the user logs in ... and c) records when the user logs out

There are still problems with this method - when you decide when the user has closed the browser and should be removed from the "log in" list ...

In short, you cannot reliably stop it ....

+1


source


I would do this using server side sessions (like php) and use load and window.unload events to set up and destroy sessions.

If a session has already been created, any window that opens after it should check the session value and force the error message to close.

0


source







All Articles