从JavaScript拦截Ctrl-N(新的浏览器窗口)? [英] Intercept Ctrl-N (new browser window) from JavaScript?

查看:91
本文介绍了从JavaScript拦截Ctrl-N(新的浏览器窗口)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎Mozilla中的Ctrl-N打开了一个新的空浏览器窗口。

这很好,我不需要对此做任何事情。


但IE中的Ctrl-N似乎克隆了当前窗口。有没有办法

拦截密钥,以便我可以在服务器端做一些事情来使新窗口表现正常?


(我们有一个基于JSP的webapp,它在会话中存储状态。现在如果两个窗口访问(并修改!)同一个会话,那么疯狂将

结果。所以我想克隆服务器端会话。那就是用b * b方式,用户可以做他们期望的 - 他们点击Ctrl-N然后他们

有两个应用程序实例,他们可以独立地与

进行交互。)



It seems that Ctrl-N in Mozilla opens a new empty browser window.
That''s fine, I don''t need to do anything about it.

But Ctrl-N in IE appears to clone the current window. Is there a way
to intercept the key so that I can do stuff on the server side to make
the new window behave correctly?

(We have a JSP-based webapp which stores state in the session. Now if
two windows access (and modify!) the same session, then madness will
result. So I''d like to clone the server-side session, as well. That
way, users can do what they expect -- they hit Ctrl-N and then they
have two instances of the application that they can interact with
independently.)

Kai

推荐答案

" Kai Grossjohann" < ka*@emptydomain.de>在消息中写道

news:87 ************ @ emptyhost.emptydomain.de ...
"Kai Grossjohann" <ka*@emptydomain.de> wrote in message
news:87************@emptyhost.emptydomain.de...
似乎在Ctrl-N中Mozilla打开一个新的空浏览器窗口。这很好,我不需要对此做任何事情。

但IE中的Ctrl-N似乎克隆了当前窗口。是否有办法拦截密钥,以便我可以在服务器端执行操作以使新窗口正常运行?

(我们有一个基于JSP的webapp在会话中存储状态。
现在,如果两个窗口访问(并修改!)相同的会话,那么将导致疯狂。


是吗?也许你应该考虑创建更强大的会话

交互代码。

所以我想克隆服务器端会话。那个
用户可以按照自己的意愿行事 - 按Ctrl-N然后
他们有两个应用程序实例,可以独立进行交互。)
It seems that Ctrl-N in Mozilla opens a new empty browser
window. That''s fine, I don''t need to do anything about it.

But Ctrl-N in IE appears to clone the current window. Is
there a way to intercept the key so that I can do stuff on
the server side to make the new window behave correctly?

(We have a JSP-based webapp which stores state in the session.
Now if two windows access (and modify!) the same session, then
madness will result.
Does it? Perhaps you should be looking at creating more robust session
interaction code.
So I''d like to clone the server-side session, as well. That
way, users can do what they expect -- they hit Ctrl-N and then
they have two instances of the application that they can interact
with independently.)




客户端(JavaScript)修复不会有帮助(特别是如果他们

涉及拦截键盘事件),因为它不是那么可靠。

因此,通知服务器

创建新窗口的重要程度也是它不适用的程度。 ate

尝试使用客户端脚本来完成任务。修复

服务器端代码,以便它可以处理多个窗口交互

与同一个会话。


Richard。



Client-side (JavaScript) fixes are not going to help (especially if they
involve intercepting keyboard events) as it is just not that reliable.
So the degree to which it is important to notify the server of the
creation of a new window is also the degree to which it is inappropriate
to attempt to use client side scripting for the task. Fix the
server-side code so that it can cope with multiple window interacting
with the same session.

Richard.


" Kai Grossjohann" < ka*@emptydomain.de> schrieb im Newsbeitrag

新闻:87 ************ @ emptyhost.emptydomain.de ...
"Kai Grossjohann" <ka*@emptydomain.de> schrieb im Newsbeitrag
news:87************@emptyhost.emptydomain.de...
似乎Ctrl-N in Mozilla打开一个新的空浏览器窗口。
这没关系,我不需要做任何事情。

但IE中的Ctrl-N似乎克隆了当前窗口。有没有办法拦截密钥以便我可以在服务器端做一些事情来使新窗口正常运行?

(我们有一个基于JSP的webapp在会话中存储状态。现在如果两个窗口访问(并修改!)相同的会话,那么疯狂将会结果。所以我想克隆服务器端会话,以及那个方式,用户可以做他们期望的事情 - 他们点击Ctrl-N然后他们有两个应用程序实例,他们可以独立地与之交互。)
It seems that Ctrl-N in Mozilla opens a new empty browser window.
That''s fine, I don''t need to do anything about it.

But Ctrl-N in IE appears to clone the current window. Is there a way
to intercept the key so that I can do stuff on the server side to make
the new window behave correctly?

(We have a JSP-based webapp which stores state in the session. Now if
two windows access (and modify!) the same session, then madness will
result. So I''d like to clone the server-side session, as well. That
way, users can do what they expect -- they hit Ctrl-N and then they
have two instances of the application that they can interact with
independently.)




似乎IE打开了一个没有名字的新窗口,即使原来的

有一个名字。所以你可以尝试类似的东西(对不起,我不知道

JSP语法):

- 在启动应用程序之前在条目页面中创建会话

- 使用window.open()在新窗口中启动应用程序并使用会话ID作为

窗口名称

- 放入脚本头部有点像


if(top.name!=" [输入会话ID在这里]"){

location.replace(" [输入页面名称在这里]?sessionclone = yes");

}


- 在服务器端,检查sessionclone getvariable。


HTH

Markus



It seems that IE opens the new window without a name even if the original
one has a name. So you could try something like (I am sorry I don''t know the
JSP syntax):
- Create the session in an entry page before starting the application
- Start the app in a new window with window.open() and use the session id as
window name
- Put a script in the head some like

if(top.name != "[input session id here]") {
location.replace("[input page name here]?sessionclone=yes");
}

- At the server side you check for the sessionclone getvariable.

HTH
Markus


" Richard Cornford" <日***** @ litotes.demon.co.uk>写道:
"Richard Cornford" <Ri*****@litotes.demon.co.uk> writes:
" Kai Grossjohann" < ka*@emptydomain.de>在消息中写道
新闻:87 ************ @ emptyhost.emptydomain.de ...
"Kai Grossjohann" <ka*@emptydomain.de> wrote in message
news:87************@emptyhost.emptydomain.de...

(我们有一个基于JSP的在会话中存储状态的webapp。
现在如果两个窗口访问(并修改!)相同的会话,那么将导致疯狂。
是吗?也许你应该考虑创造更多强大的会话
交互代码。

(We have a JSP-based webapp which stores state in the session.
Now if two windows access (and modify!) the same session, then
madness will result.
Does it? Perhaps you should be looking at creating more robust session
interaction code.




似乎我无法想到更好的设计.webapp有

查询和结果列表。它提供了比一个查询和同一会话中的多个结果列表显示更多

的功能;查询/结果列表的

标识符存储在URL。


让我们说我正在查看ResultList.jsp?id = foo,它给出结果列表的

的id。现在我点击一个列标题,这意味着按该列对结果列表进行排序

。然后webapp修改会话

属性以指示已排序的b y列X,然后重新调用

ResultList.jsp?id = foo。 JSP在会话中查找结果

列表并将其可视化。


这两步方法很有用,因为它意味着重新加载

按钮将始终有效:

窗口位置栏中显示的URL只是从会话中读取当前状态,所有用户操作

first修改会话然后重定向回相同的

会话显示网址。


现在按Ctrl-N表示两个窗口将显示相同的会话

属性(由id = foo标识)。现在,用户在一个窗口中对一个列进行排序,然后在另一个窗口中重新加载,然后另一个窗口将显示用户为第一个窗口设置的排序顺序

窗口。


如何解决这个问题?



It seems I was unable to think of a better design. The webapp has
queries and result lists. It provides functionality for showing more
than one query and more than one result list in the same session; an
identifier for the query/result list is stored in the URL.

Lets''s say I''m viewing ResultList.jsp?id=foo, which gives the id of
the result list. Now I click on a column heading which means to sort
the result list by that column. Then the webapp modifies the session
attribute to indicate "sorted by column X", then reinvokes
ResultList.jsp?id=foo. That JSP looks in the session for the result
list and visualizes it.

This two-step approach is useful because it means that the reload
button will always work: the URL shown in in the location bar of the
window just reads the current state from the session, all user actions
first modify the session then redirect back to the same
session-display URL.

Now hitting Ctrl-N means that two windows will show the same session
attribute (identified by id=foo). Now the user sorts on a column in
one window and hits reload in another window, and then the other
window will display the sort order set by the user for the first
window.

How to solve this problem?

所以我''也想克隆服务器端会话。那样,用户可以按照他们的预期行事 - 他们点击Ctrl-N然后
他们有两个应用程序实例,他们可以独立地进行交互。)
So I''d like to clone the server-side session, as well. That
way, users can do what they expect -- they hit Ctrl-N and then
they have two instances of the application that they can interact
with independently.)

<客户端(JavaScript)修复不会有帮助(特别是如果它们涉及拦截键盘事件),因为它不是那么可靠。



Client-side (JavaScript) fixes are not going to help (especially if they
involve intercepting keyboard events) as it is just not that reliable.




实际上,我想截取新窗口的创建,而不是按下Ctrl-N的

用户...有些浏览器可能会使用不同的kbd

快捷方式。

因此,通知服务器创建新窗口的重要程度也是不合适的程度。使用客户端脚本来完成任务。修复
服务器端代码,以便它可以处理与同一会话的多个窗口交互。



Actually, I wanted to intercept the creation of a new window, not the
user hitting Ctrl-N... Some browsers might use different kbd
shortcuts.
So the degree to which it is important to notify the server of the
creation of a new window is also the degree to which it is inappropriate
to attempt to use client side scripting for the task. Fix the
server-side code so that it can cope with multiple window interacting
with the same session.




如果这很容易。 ..





If it was that easy...

Kai


这篇关于从JavaScript拦截Ctrl-N(新的浏览器窗口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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