问题
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)
exist something like that?
Regards, Shadow.
回答1:
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.
回答2:
Not possible with javascript, and with good reason.
Do you really want websites to start redirecting your other tabs?
回答3:
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.
来源:https://stackoverflow.com/questions/5419177/get-opened-pages-tabs-with-mootools