Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect that the same page is already opened in another window in IE

Is there any way to check that my page is not opened in another tab or window in IE? Say I have Page1 and user hits "new window", which will open a new window with the same page opened. So now there are two instances of the page. I want to restrict the browser to only have one instance of the page opened at any given time.

One of the requirements is that users must be able to refresh the page and still be in the same state inside the application. So one-time tokens are not suitable.

Not sure that there is any way to distinguish between a page refresh and a new window opened, that's why I'm asking.

P.S. This is not for a normal website, and I understand that doing this usually would be intrusive and evil. There is a strong case to do this here, as it is a massive web application.

like image 910
Egor Pavlikhin Avatar asked Apr 14 '10 23:04

Egor Pavlikhin


2 Answers

The best way to implement this is by having a server side token (many banks do this) that is regenerated at each request and must be passed back for the pages to function.

So basically:

  1. You append a generated token to each link (as a part of the query string)
  2. Any request that you recieve that does not contain the token can be considered invalid.
  3. Generate a new token at each request so that only 1 token is valid at any 1 time
like image 97
Josiah Avatar answered Sep 23 '22 01:09

Josiah


Easy way to do it is to use windowName

window.open(windowURL, windowName, windowFeatures); 

assign it somethign unique and check it when the link is clicked to make sure that hasn't been open already.

this guy explains it realy good. - http://www.joemarini.com/tutorials/tutorialpages/window1.php

like image 31
drusnov Avatar answered Sep 23 '22 01:09

drusnov