0

I have a site that need to know if the user have other pages/tabs opened just to make actions in them (like closing them, redirect etc..). I'm not talking about popups, I'm talking about content opened in a new page tab manually by the user.

So basically I need a method to get a list of tabs/windows opened on my domain and be able to access the content in them (as all is the same domain, there should not be any security problems)

Does something like that exist?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
shadow_of__soul
  • 429
  • 1
  • 8
  • 19

2 Answers2

0

I think it might be possible, since you say it's all on the same domain.

When a page/tab gets loaded, you want to assign it an unique id and send it to the server. When it gets closed you will need to tell the server about it as well, so the server knows what tabs are still open. In each open tab you can then regularly query the server for any actions that you want to happen in this tab, like redirecting or closing it.

eikes
  • 4,811
  • 2
  • 31
  • 31
  • yes, i thinked about this option but i wanted something more client side solution, and not to keep a record of tabs in the server (something like myTab.element.whatever in JS) – shadow_of__soul Mar 24 '11 at 14:11
  • the only way to keep track of opened things is if you use window.open on all your links. this still won't work if the user duplicates a tab or a window or opens another link out of their bookmarks. – Dimitar Christoff Mar 24 '11 at 15:22
  • ok, then i will need to do something server based then, seems that there is nothing like what i need :) – shadow_of__soul Mar 24 '11 at 15:43
  • you can also do the same with Cookies :) you will still need to add some polling to detect changed values, but the solution will be completely client side (all tabs in same domain === all tabs can access the same set of cookies). – gonchuki Mar 26 '11 at 04:02
0

Actually, this IS possible, and you don't need to go through constant server requests. Use localStorage, and bind to the storage event. The implementation is actually really simple. The only serious gotcha is that not all browsers follow the specification for whether the storage event is fired on the origin window, but with a few lines of code you can normalize the behavior.