检测CTRL-N或用户打开新窗口的方式 [英] Ways to detect CTRL-N or when a user opens a new window

查看:146
本文介绍了检测CTRL-N或用户打开新窗口的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何检测用户何时打开新窗口.用户已通过身份验证,我们大量使用了会话.

How can we detect when a user opens a new window. The user is already authenticated and we make heavy use of sessions.

我们试图避免 Ctrl + N javascript钩子,但这也许是一个选择.

We were trying to avoid Ctrl+N javascript hooks but maybe that is an option.

我假设请求是完全相同的URL ...使用 Ctrl + N ?

I am assuming the request is the exact same URL...with Ctrl+N?

推荐答案

我们试图避免ctrl-n javascript钩子

We were trying to avoid ctrl-n javascript hooks

算了.从理论上讲,您可以尝试使用Control键修饰符捕获'​​n'的按键事件,但还有许多其他方式可以更可能使用新窗口或标签,并且您将无法使用去抓. File-> New Window/Tab,中键单击或Shift键单击链接,中键单击后退/前进按钮,右键单击在新窗口中打开,在新选项卡中打开书签,双击浏览器图标...

Forget it. Whilst you could in theory try to catch keypress events for ‘n’ with the Control key modifier, there are any number of other ways to open a new window or tab which may be more likely to be used, and you won't be able to catch. File->New Window/Tab, middle click or shift-click link, middle click back/forward buttons, right-click-open-in-new-window, open bookmark in new tab, double-click browser icon...

用户已经通过身份验证,我们大量使用会话.

The user is already authenticated and we make heavy use of sessions.

这本身不应该是问题.我猜您的意思是您的应用程序正在转储不应有的会话中的各种特定于页面的数据,现在您发现打开了多个窗口时应用程序中断了?好吧,敬意和愉快的重写.

That shouldn't be a problem in itself. I guess what you mean is that your application is dumping all sorts of page-specific data in the session that it shouldn't have, and now you find the application breaks when you have more than one window open on it? Well, commiserations and happy rewriting.

与此同时,您所能做的就是告诉用户请不要尝试在同一应用程序上打开两个浏览器窗口".有一些可能的方法可以使一个页面上的JavaScript注意到JavaScript同时在同一域中的另一个页面上运行,通常涉及使用document.cookie作为页面间通信管道.但这也有点脆弱.

In the meantime about all you can do is tell the user "please don't try to open two browser windows on the same application". There are potential ways you can make JavaScript on one page notice that JavaScript is running on another page in the same domain at the same time, generally involving using document.cookie as a inter-page communications conduit. But that's also a bit fragile.

这篇关于检测CTRL-N或用户打开新窗口的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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