Is it possible to detect if a user has opened a link in a new tab?

后端 未结 7 1923
梦谈多话
梦谈多话 2020-11-27 15:33

If a user is on your website and opens another link (also to your website) in a new tab, is it possible to differentiate this from the user just clicking on the link normall

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 16:30

    This is what I use in ASP.NET MVC to forbid authenticated users to open multiple tabs:

    
    

    Basically, this sets the window name first time when the user visits the login page. After logging in, for each subsequent page load the window name is tested.

    Two problems:

    • does not wok if JavaScript disabled
    • if by mistake the user closes the original tab and then pastes some other link to my website in the address bar, the user will always receive the error page. To give the user a chance to recover, I have included "Log out" link in the SingleTab.htm page, so the user can destroy his session cookie and start a new session.

提交回复
热议问题