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 开发者_JS百科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?
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.
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.
精彩评论