鼠标在哪个窗口? [英] Over which window is the mouse?

查看:61
本文介绍了鼠标在哪个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个JavaScript应用程序打开第二个窗口。哪个是检测鼠标两个窗口(如果有的话)的最佳方法?

首先我想到了document.onmouseout和document.onmouseover(两者都是

windows)是这样做的方法,但是有些浏览器(比如Firefox)似乎即使鼠标在文档中传递也会触发这些(例如来自

空体背景到div),无论如何,

文件的任何子元素都会获取文件之前的事件(事件冒泡),所以我的

脚本仍然会思考鼠标在另一个窗口上方。使用

onfocus / onblur似乎也不是正确的想法,因为它需要

类似于窗口中的点击来触发它们。现在,我能想到的唯一更多或更少有希望的方法是在我想要处理事件的每个对象上设置对相应的

窗口的引用。但是接下来我将不得不关注这将产生的循环引用

。那我该怎么办?

有一个简单的解决方案吗?


提前感谢您的建议,

Thomas

解决方案



" Thomas Mlynarczyk" < BL ************* @ hotmail.com>在消息中写道

news:d6 ************* @ news.t-online.com ...



我有一个JavaScript应用程序打开第二个窗口。哪个是检测鼠标两个窗口(如果有的话)的最佳方法?


我可能会遗漏一些东西,但你不想查看哪个窗口有
焦点?


Jay


首先我认为document.onmouseout和document.onmouseover(对于两个窗口)都是这样做的,但有些浏览器(如Firefox)似乎<即使鼠标在文档中传递(例如从
空体背景到div),也可以触发这些,并且无论如何,
文档的任何子元素都会"获得"文件之前的事件(事件冒泡),所以
我的
脚本仍然会思考鼠标在另一个窗口上方。使用
onfocus / onblur似乎也不是正确的想法,因为它需要
类似于窗口中的点击来触发它们。现在,我能想到的唯一不那么有希望的方法是在我想要处理事件的每个对象上设置对相应
窗口的引用。但是接下来我将不得不关注这会产生的循环引用。那我该怎么办?是否有一个简单的解决方案?

提前感谢您的建议,
Thomas



Thomas,


我认为我有一个解决方案。


1)将onMouseMove事件附加到两个窗口。

2)处理程序函数应该更改一个变量,该变量将表示Hovered和Hovered。窗口名称或ID


比您可以检查此变量以获得答案。

来自第二个窗口使用window.opener.handlerName
< br $>
我在firefox上试过这个解决方案......没关系。


祝你好运

<另外,杰克:

" Thomas Mlynarczyk" < BL ************* @ hotmail.com>在消息中写道
新闻:d6 ************* @ news.t-online.com ...


是检测鼠标两个窗口(如果有的话)的最佳方法?



我可能会遗漏一些东西,但不会你想检查哪个窗口有焦点?




如果窗口A有焦点,我只需移动鼠标(没有按下按钮,没有

点击,也没有任何东西)到窗口B - 那会单独改变焦点

已经?


Hi,

I have a JavaScript application which opens a second window. Which is the
best way to detect over which (if any) of the two windows the mouse is?
First I thought document.onmouseout and document.onmouseover (for both
windows) would be the way to do it, but some browsers (like Firefox) seem to
fire these even when the mouse passes within the document (like from the
"empty body background" to a div), and anyway, any child elements of
document would "get" the events before the document (event bubbling), so my
script would still "think" the mouse is over the other window. Using
onfocus/onblur does not seem to be the right idea either as it would require
something like a click in a window to trigger them. Now the only more or
less promising way I can think of is to set a reference to the respective
window on each object I want to handle events for. But then I''d have to take
care about the cyclic references this would create. So what could I do? Is
there a simple solution?

Thanks in advance for your advice,
Thomas

解决方案


"Thomas Mlynarczyk" <bl*************@hotmail.com> wrote in message
news:d6*************@news.t-online.com...

Hi,

I have a JavaScript application which opens a second window. Which is the
best way to detect over which (if any) of the two windows the mouse is?
I might be missing something but wouldn''t you want to check which window had
focus?

Jay

First I thought document.onmouseout and document.onmouseover (for both
windows) would be the way to do it, but some browsers (like Firefox) seem
to
fire these even when the mouse passes within the document (like from the
"empty body background" to a div), and anyway, any child elements of
document would "get" the events before the document (event bubbling), so
my
script would still "think" the mouse is over the other window. Using
onfocus/onblur does not seem to be the right idea either as it would
require
something like a click in a window to trigger them. Now the only more or
less promising way I can think of is to set a reference to the respective
window on each object I want to handle events for. But then I''d have to
take
care about the cyclic references this would create. So what could I do? Is
there a simple solution?

Thanks in advance for your advice,
Thomas



Hi Thomas,

I think that I have a solution for you.

1) Attach an onMouseMove event to the body of both windows.
2) The handler functions should change a variable which will indicate
the "Hovered" window name or id

than you can check this variable to get your answer.
from the second window use window.opener.handlerName

I Tried this solution on firefox ... and it''s OK.

good luck


Also sprach Jay:

"Thomas Mlynarczyk" <bl*************@hotmail.com> wrote in message
news:d6*************@news.t-online.com...

Hi,

I have a JavaScript application which opens a second window. Which
is the best way to detect over which (if any) of the two windows the
mouse is?



I might be missing something but wouldn''t you want to check which
window had focus?



If window A has the focus and I simply move the mouse (no button pressed, no
clicking, nor anything) to window B - would that alone change the focus
already?


这篇关于鼠标在哪个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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