40931

How to avoid opening two browser windows?

I'd like to avoid the possibility to open two application windows (or tabs). It is, if my app (LAMP+Javascript) is installed on http://www.domain.com and the user is browsing the page http://www.domain.com/user/ he/she cannot open another window like http://www.domain.com/system/. If he/she opens another window, the application should show an error message.

Is that possible?

<strong>For curious people</strong>: I need this behaviour because my app uses some session data to identify sequences of actions. If the user opens a new window on the same browser, normally everything is right, but if he/she starts a new sequence, the previous one (in the other window) will be lost.

Answer1:

While it is correct what all others said here that you cannot prevent someone from opening your website twice, there might be a workaround for you. Note that this is not a 100% solution and will require you to develop further code based on this.

As far as I understand you have the following problems:

<ol> <li>How to determine if a user has your page open with a window/tag that shares session data (i.e. two tabs in Chrome, 2 Chrome windows etc.) - that is the easiest part though.</li> <li>How to determine if a user has your page open in a different browser (i.e. open in FF & Chrome at one time) - that is the tricky one.</li> </ol>

However - you could use LSO - Local Shared Objects to accomplish this. These are Flash based cookie similar data pieces stored at the client's side. AND THEY ARE CROSS-BROWSER & CROSS-DOMAIN COMPATIBLE. You can find a nice library called EVERCOOKIE for using them here.

By setting such a cookie you will be able to trace the user even if he opens a new window or even if he opens your page in a different browser, as far as the browsers share the same Flash installation etc.

Note that this will not prevent someone in opening two windows directly, but it enables you to send him to the same sequence state as he is in the other window for example.

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 normal users would not be able to get it...

Answer2:

You <strong>cannot</strong> prevent someone from opening your website twice.

You might by able to use a new session key for every page, but that can get a bit hanky...

Answer3:

As mentioned above — you cannot prevent someone from opening your website twice. Yet your problem is, as I see, to actually mare sure that every browser session is unique. There are many approaches to reach this, one could be to generate a random number by the client and send it via ajax to the backend to be used instead of a session-id, you might have some persistence problems, but these are all easy to tackle.

Answer4:

The only way I can think of doing this is to hide / remove content if the user is logged in somewhere else

So you would a) need the user to login ... and b) record when the user logged in ... and c) record when the user logged out

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

In short the answer is you cant reliably stop this ....

Answer5:

I would do it using sessions on the server side (i.e php) , and utilize the load and window.unload events to set and destroy sessions.

If a session is already created, then any window that opens up after that , should check for the session value, and force a close after showing an error message.

Recommend

  • Updating a record in Elm
  • .NET 3.5 SP1 network shares allow exe application to run
  • Can multiple Android IntentServices run at the same time?
  • SQL Table / Sub-Query Alias Conventions
  • “Drawing” an arc in discrete x-y steps
  • How can I fast-forward a branch without checking it out
  • Can a MEF application built on .NET 4 import types built against .NET 3.5?
  • Java Netbeans Error Cannot find symbol, symbol: class out, location: class System, expected, illega
  • Access 2007 forms with parameterized RecordSource
  • Opening links in a new tab and only the new tab
  • How to determine the CCSID used in CPYFRMIMPF command?
  • XBee Linux Serial Port on Rasberry Pi
  • Opening two instances of InAppBrowser (_system and _blank) prevents events from triggering
  • How to discover Font Type?
  • Django model inheritance, filtering models
  • How can I set a binding to a Combox in a UserControl?
  • Is playing sound in Javascript performance heavy?
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Use of this Javascript
  • Chrome doesn't support silverlight anymore? How to solve this?
  • C++ Partial template specialization - design simplification
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • How to rebase a series of branches?
  • Using jQuery closest() method with class selector
  • Get one-time binding to work for ng-if
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Array.prototype.includes - not transformed with babel
  • Problems to linebreak with an int in JLabel
  • Volley JsonObjectRequest send headers in GET Request
  • Javascript convert timezone issue
  • Importing jscolor library in angular 2
  • How to get next/previous record number?
  • Python: how to group similar lists together in a list of lists?
  • Acquiring multiple attributes from .xml file in c#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • java string with new operator and a literal