检测文档外部的点击
我在检测文档外部的单击事件时遇到问题,例如在浏览器的关闭按钮中而不使用 onbeforeunload 事件,因为我有一个正在处理某些内容的 JSP 页面,使用元刷新来提供流程演变的状态。
由于我使用元刷新,我无法使用 window.onbeforeunload 事件来阻止/确认用户退出,因为元刷新将触发该事件。因此,我需要手动检查鼠标是否会在文档外部单击。
我可以检查鼠标坐标是否在外部,因此无法将单击事件与 IE8 中的单击事件关联起来。
if (window.event.clientY < 82 && window.onclick)
有人有任何想法来解决这个问题吗?
提前致谢!
I am having a problem to detect a click event outside document, for instance in the closing button of the browser without using the onbeforeunload event, because I have a JSP page that is processing something, using meta refresh to give the status of the process evolution.
Since I am using meta refresh I cannot use window.onbeforeunload event to prevent/confirm the user to exit because the meta refresh will fire up the event. Thus, I need to check manually if the mouse will be clicked outside my document.
I can check if the mouse coordinates are outside, thus can´t associate an click event to that in IE8.
if (window.event.clientY < 82 && window.onclick)
Someone have any idea out achieve this issue?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无法检测关闭按钮,但您可以通过执行以下操作来检测用户是否失去浏览器焦点:
Detecting the close button isn't possible but you can detect if the user is losing focus of the browser by doing:
这是不可能的。事件不会在文档外部触发,包括窗口镶边上的单击。
It's not possible. Events don't fire outside of the document, including clicks on the window chrome.
我认为您需要考虑一下您想要实现的目标。如果您必须获取页面的关闭事件,这听起来像是一个不稳定的设计。如果您担心这一点,许多其他事件也会影响您。
如果您有一个 JSP 页面通过元刷新生成并显示状态 - 窗口关闭有什么问题?这应该是您关心的问题,而不是如何检测浏览器关闭事件。
I think you will need to think about what you're trying to achieve. It sounds like a shaky design if you must get the close event of the page. Lots of other events will affect you if that is of a concern.
If you have a JSP page producing and showing the status by a meta refresh - what is your problem with the window closing? That should be of your concern, not how to detect a browser close event.