客户端脚本变量的作用域多个打开的浏览器问题的标签 [英] Client side script variables scope for multiple opened tabs of browser issue

查看:112
本文介绍了客户端脚本变量的作用域多个打开的浏览器问题的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery脚本我的共享 _Layout.cshtml ,其中记录了最后点击的特定的时间间隔后注销的用户。所产生的问题是,当超过10页的运行结束(即,在浏览器中的多个选项卡,同一应用的不同页面被打开),如果有任何页仍闲置指定的时间,这将注销用户。并且该用户当前工作时,当用户点击,它会抛出异常(这是显而易见的,因为用户已经被其他网页登出),其他页面。我不能使用会议相关的东西。反正有,我能保持这样类型的不同的浏览器不同的打开的标签变量的范围是什么?我想其他打开的标签的计时器归零,如果用户正在使用的任何打开的选项卡。我试着到处寻找答案第一,但我发现相比于我的方案不同的每一个问题。

I have a jquery script in my shared _Layout.cshtml, which records the last click and logs out the user after a specific time interval. The problem that arises is that when more than 1 pages are opend (i.e, in multiple tabs of browser, different pages of same application are opened), if any page remains idle for specified time, it logs out the user. and the other page that the user is currently working on, when user clicks, it throws exception (which is obvious, because user has been logged out by other page). I cannot use sessions related stuff. is there anyway, i can maintain scope of such type of variables across different opened tabs of browser? I want to reset the timer of other opened tabs to zero, if user is working on any of the opened tabs. I tried to look around for the answer first, but i found every issue different as compared to my scenario.

(我使用MVC 4 jQuery脚本在/共享/ _Layout.cshtml

(I'm using MVC 4. Jquery script is in /Shared/_Layout.cshtml)

推荐答案

我解决它使用一些库,叫做的 store.js 的。它不需要轮询服务器之类的东西,而是一个cookie只是瞬间划过标签共享,很快它被设置在任何打开的标签(中无需标签刷新,通常是为了要求得到的cookie,其他一些选项卡中设置)。和高于一切,我爱这个是 store.js 使用的localStorage 时可用,并且回落的用户数据行为的 IE6 的和的 IE7 的。无闪光灯放慢你的页面加载。没有cookies来养肥你的网络请求。 store.js取决于JSON序列化到磁盘。这是非常简单易用。

I solved it using some library, called store.js. It doesn't require polling server and stuff, instead, a cookie is simply shared instantly across the tabs, very soon as it is set on any of the opened tabs (without the need for tab to refresh; which normally is required in order to get cookie, set on some other tab.). and above all, what i loved about this is that store.js uses localStorage when available, and falls back on the userData behavior in IE6 and IE7. No flash to slow down your page load. No cookies to fatten your network requests. store.js depends on JSON for serialization to disk. It's very simple to use.

使用示例:

store.set('username', 'joe')
document.write('username: ' + store.get('username') + '<br />')
store.remove('username')
store.clear()
store.set('user', { name: 'joe', likes: 'javascript' })
var user = store.get('user')
document.write(user.name + ' likes ' + user.likes)

这篇关于客户端脚本变量的作用域多个打开的浏览器问题的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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