IE:为什么event.ClientY在某些客户端机器上总是否定的? [英] IE: Why is event.ClientY always negative on some client machines?

查看:131
本文介绍了IE:为什么event.ClientY在某些客户端机器上总是否定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个安装在Intranet上的应用程序,可以通过IE访问。如果用户关闭浏览器,我们想要做某些事情(例如,使用浏览器右上角的X),但如果用户点击链接转到其他页面则不行。所以在javascript中,我们想要检测这种情况。建议的最常见解决方案是在onunload或onbeforeunload函数中,检查event.ClientY是否为负数。如果它是否定的,则用户单击X以关闭浏览器。我知道这不是完全可靠的,但它只需要在IE中工作。这是一个例子:

We have an application that is installed on an intranet and is accessed with IE. There are certain things that we want to do if the user closes the browser (e.g. using the X in the upper right hand corner of the browser) but not if the user clicks on a link to go to a different page. So in javascript, we want to detect this condition. The most common solution suggested is that in the onunload or onbeforeunload function, check to see if event.ClientY is negative. If it's negative, then the user has clicked the X to close the browser. I know this is not completely reliable, but it only needs to work in IE. Here's an example:

http://www.coderanch.com/t/122627/HTML-CSS-JavaScript/Generic-code-Detect-Brower-Close

这是我们的问题:有些客户端计算机,当用户点击页面上应该将它们发送到另一个页面的链接时,event.clientY值总是负数,然后运行我们的javascript,它只应该在关闭浏览器时运行。 event.clientX和event.clientY始终被卡在相同的负值中,无论我点击的页面上的链接在哪里。我在这样做的客户端计算机上看不到任何不同(例如IE版本或设置或兼容性视图或服务器是可信站点)。如果我在onclick函数中提醒event.clientY,它似乎是正确的。它只是在onunload和onbeforeunload函数中作为负值停留。

Here's our problem: There are certain client computers where, when the user clicks on a link on the page that is supposed to send them to another page, the event.clientY value is always negative, which then runs our javascript that is only supposed to be run when they close the browser. event.clientX and event.clientY are always stuck as the same negative values, no matter where the link is on the page that I click on. I can't see anything different on the client computers that do this (e.g. IE version or settings or compatibility view or if the server is a trusted site). If I alert event.clientY in an onclick function, it seems to be correct. It's only stuck as a negative value in the onunload and onbeforeunload functions.

关于为什么会发生这种情况或IE设置可能导致它的任何想法?

Any ideas on why this is happening, or what IE settings might be causing it?

推荐答案

OP中的javascript被这个Microsoft 2013年7月更新打破(这在已知问题部分中甚至得到承认):

The javascript in the OP was broken by this Microsoft July 2013 update (this is even acknowledged in the "Known issues" section):

http://support.microsoft。 com / kb / 2846071 / zh-gb

但它在2013年8月更新中得到修复:

But it was fixed in this August 2013 update:

http://support.microsoft.com/kb/2862772

我已经确认我安装8月更新的客户不再有问题。

I have confirmed that clients on which I install the Aug update no longer have the issue.

这篇关于IE:为什么event.ClientY在某些客户端机器上总是否定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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