[英]How to prevent user from opening the application in multiple browser tabs?
We are looking for a way to prevent users from opening the application in multiple tabs under the same browser.我们正在寻找一种方法来防止用户在同一浏览器下的多个选项卡中打开应用程序。
The idea is to get plugged into one of the query Filter and then get access to the session maybe, and check if there is an already opened tab before proceeding.这个想法是插入其中一个查询过滤器,然后访问 session 可能,并在继续之前检查是否有已打开的选项卡。
I looked into httpSession
and HttpRequest
stuff but found nothing that can help.我查看了
httpSession
和HttpRequest
的东西,但没有发现任何帮助。
Is there any functionality in the java side to know if the app is already opened in another tab? java 端是否有任何功能可以知道该应用程序是否已在另一个选项卡中打开?
thanks,谢谢,
There's ways to accomplish this with Javascript.使用 Javascript 可以实现此目的。
See past questions / answers查看过去的问题/答案
But all of those javascript techniques fail to work if...但是,如果...
You'll wind up with a mix of feature to attempt to prevent this (but it's a losing battle, and there's countless ways to get around it).您最终会使用多种功能来尝试防止这种情况发生(但这是一场失败的战斗,并且有无数种方法可以绕过它)。
If you have a login, you'll want to track past logins and offer to disconnect / invalidate those other logins on a new login.如果您有登录名,您将需要跟踪过去的登录名并提供在新登录名时断开/使其他登录名无效。 (this will help with the multiple browsers and devices attempts).
(这将有助于多个浏览器和设备的尝试)。 Your authorization layer on your server side will invalidate old sessions if they are attempted to be used.
如果尝试使用旧会话,则服务器端的授权层将使旧会话无效。
If you have multiple tabs in the same browser, the javascript techniques from the old questions/answers are probably the best.如果您在同一个浏览器中有多个选项卡,那么旧问题/答案中的 javascript 技术可能是最好的。
There are also people attempting to use websocket to act as the single point of communication, but I don't understand how that could work, but you'll come across it in your research.也有人试图使用 websocket 作为单点通信,但我不明白它是如何工作的,但你会在研究中遇到它。
From the server's perspective, it doesn't matter if the requests come from the same browser tab, different tabs, different browsers or different devices.从服务器的角度来看,请求来自相同的浏览器选项卡、不同的选项卡、不同的浏览器或不同的设备都没有关系。 Two tabs can share the same session.
两个选项卡可以共享同一个 session。 There is no way for the server (or the servlet) to know whether the request came from tab A or tab B. Tabs are a browser feature, it doesn't get sent in the HTTP header.
服务器(或 servlet)无法知道请求是来自选项卡 A 还是选项卡 B。选项卡是浏览器功能,它不会在 HTTP header 中发送。
If you would elaborate on why you want to do this, I might be able to give a better answer.如果您详细说明为什么要这样做,我可能会给出更好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.