用户在同一浏览器上的同一应用程序上打开新选项卡时注销用户的代码 [英] Code to logout a user when he opens a new tab on same application on same browser

查看:73
本文介绍了用户在同一浏览器上的同一应用程序上打开新选项卡时注销用户的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序URL为xyz.com时实现逻辑假设用户在我的应用程序xyz.com中登录,并且当同一用户在同一浏览器的新选项卡中打开相同的应用程序时我想要注销该用户这通常发生在银行网站上。

我一直在使用这个javascript以及sessionStorage概念,我从一个中央代码隐藏页面调用当有人登录javascript方法时调用true参数并检查使用会话varioable,每个新选项卡设置为1

所以每当用户使用logedin和新选项卡时它会退出

一切正常,只是一个当我按住ctrl按钮并通过单击应用程序的任何链接打开一个新选项卡时,新选项卡中的sessionStorage变量保存最后一个选项卡值,这里就是我面临的问题!!

如何解决这个问题我无法禁用或停止应用程序中的ctrl按钮,因为它有可能这样做!!





I want to implement a logic when say my application url is xyz.com suppose a user is login in my application xyz.com and when the same user opens the same application in new tab of same browser i want to logout that user which generally happens in banking websites.
I have been using this javascript along with sessionStorage concept, i am calling from a central codebehind page when some one is login the javascript method is called with true parameter and it check with the session varioable which is set to 1 for each new tab opened
so whenever a user is logedin and a new tab it gets logout
All is working fine,just a little issue is there when i hold ctrl button and open a new tab by clicking on any link of the application the sessionStorage variable in the new tab holds the last tab value, here is where i am facing the problem !!
How to resolve this i cant disable or stop the ctrl button in the application as it is probhited to do so !!


function MultiTabLogOut(strLoginFlag)
{
        alert(strLoginFlag);
        if (sessionStorage.clickcount) {
            sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;
            }
       else{
            sessionStorage.clickcount = 1;
        }
if(sessionStorage.clickcount<2 &&strLoginFlag =='true'){
        alert('You cant open the application in different tab of same browser!Kindly login again!');
            window.location.href='/_layouts/SignOut.aspx';
}
    }

推荐答案

我不确定这一点,但我们可以这样做。

当您的应用程序继续运行时,维护一个本地cookie,并且该cookie应该包含时间戳加上abc(无论如何),这样您就可以轻松搜索。并且使您的代码能够使您的代码每隔30秒看一次cookie cookie可用或找到然后继续,否则重定向到登录页面。当用户在新选项卡中启动应用程序时,检查abc(无论如何)已存在(如果存在)然后删除它然后创建一个此应用程序。

这样就可以删除旧版运行的应用程序cookie,因此30秒后运行的代码将会触发,并且找不到cookie,因此它将触发重定向代码。
I am not sure about this but we can proceed like this.
Maintain a local cookie when your application proceed and that cookie should contain timestamp plus "abc"(whatever) such that you can search that easily.And make your code such that your code looks that cookie in every 30 secs if the cookie is available or found then proceed otherwise redirect to login page.Now when the user start the application in new tab check for "abc"(whatever) already exist if exist then delete that and then make one this application.
This way older running application cookie is deleted so the code that is running after 30 sec will fire and will not found cookie so it will fire the redirect code.


这篇关于用户在同一浏览器上的同一应用程序上打开新选项卡时注销用户的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆