检测用户是否正在关闭IE浏览器而不是onunload事件,因为它在用户刷新等时触发 [英] To detect if the user is closing the IE browser apart from onunload event, as it is triggerred when user does refresh etc

查看:129
本文介绍了检测用户是否正在关闭IE浏览器而不是onunload事件,因为它在用户刷新等时触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去5天通过网络上的众多论坛后,我仍然无法完全追踪浏览器关闭事件。当用户试图关闭浏览器时,我的要求是生成弹出消息。

After being through numerous forums available on the net for last 5 days, I am still not able to completely track down the browser close event. My requirement is to generate a popup message, when user tries to close the browser.

我在body'onbeforeunload'事件上调用了我的javascript函数。我已经硬编码条件来检查浏览器,刷新,文件关闭或Alt-F4的红色'X'按钮的鼠标坐标。

I have called my javascript function on body 'onbeforeunload' event. And I have hardcoded the conditions to check the mouse-coordinates for the red 'X' buton of browser, refresh, File-close or Alt-F4.

当浏览器窗口最大化时,我的代码工作正常,但如果我们在限制后缩小它,则会失败。请帮助我,如果某个机构已经找到了类似问题的解决方案。

My code works fine when browser window is Maximized, but fails if we shrink it after a limit. Please help me, if some body has already found the solution to a similar problem.

谢谢。

好的,告诉我如果可以检测用户是否单击了浏览器的刷新按钮。此外,可以通过右键单击 - 刷新或Ctrl-R来触发刷新。我的要求是在Refresh上使变量为false。我只能在F5上做到这一点,但所有其他方式仍然无法实现。这同样适用于Back Buton。

Ok, just tell me if it is possible to detect if a user has clicked on the Refresh button of the browser. Also, Refresh can be triggered by Right-click - Refresh or Ctrl-R. My requirement is to make a variable false on Refresh. I am just able to do it on F5, but all other ways are still out of my reach. The same would be applied to Back buton.

您好ppl,感谢所有回复至少的人。我已经与我的老年人谈过这个问题,他们现在已经了解并且已经对浏览器菜单按钮做出了妥协。所以现在我的任务变得简单了。现在,我正在使用一个变量并默认情况下将其设置为true。正如我之前提到的,我只需捕获onbeforeunload并在用户试图离开时弹出一条消息。当用户导航到其他页面时,该消息不会弹出,因为我使用以下代码在我的页面的所有链接上将变量设为false:

Hi ppl, Thanks for all who replied atleast. I have talked to my seniors regarding this and they have now understood and have compromised with the browser menu buttons. So now my task has become easy. Now, I am using a variable and making it true by default. As, I mentioned earlier I just have to catch the onbeforeunload and popup a message when user tries to leave. The message will not popup when user is navigating to other pages, as I have made the variable as false on all the links of my page using following piece of code:

document.onclick = function() {
    //To check if user is navigating from the page by clicking on a hyperlink.
    if (event.srcElement.tagName == 'A')
        blnShowMsg = false; //To not popup the warning message
    else
        blnShowMsg = true; //To popup the warning message
}

在我的情况下,仍会显示消息用户会刷新,返回或转到收藏夹中的任何链接等。

In my case still the message is shown when user does Refresh, back or goes to any link in Favorites, etc.

感谢好友,但我已经通过了那并且也没有找到太多帮助。我的老年人对这个解决方案不满意,因为在我的应用程序的evry链接上放置一个标记是一项复杂的工作,他们害怕破坏应用程序。任何其他建议将不胜感激。再次感谢。

Thanks buddy, but I have already gone through that and didn't find much help there too. My seniors are not happy with that solution as putting a flag on evry link of my application is a complicated job and they fear of breaking the application. Any other suggestions would be appreciated. Thanks once again.

这里没有人能想到解决方案!所有专家在哪里???

Is there no one who can think of a solution here!!! where are all the experts???

推荐答案

这个问题不是一个不寻常的问题。然而,在搜索互联网5天后,你仍然没有找到满意的答案。这本身应该是一个相当简单的指标。

The question isn't an unusual one. Yet after 5 days searching the internet you still haven't found a satisfactory answer. That in itself should be a fairly plain indicator.

我在网上发现的是对无能为力答案的严重厌恶。当某些事情无法做到时,正常的反应是没有回应。

What I've found on the web is there is a serious aversion to the 'no can do' answer. When something can't be done the normal response is to make no response.

底线不仅可以做你不想做的事它不应该做。

Bottom line is not only can what you are trying do not be done it should not be done.

我认为你需要回到你的老年人那里,并向他们解释一个Web UI是由浏览器托管的来宾客户机器。此来宾状态是一个重要的状态。

I think you need to go back to your seniors and explain to them that a Web UI is a guest hosted by a browser on a client machine. This guest status is an important one.

您是否希望家中的访客有权强制您在发送时提醒他们想上厕所吗?否?

Would you want a guest in your home to have the power to enforce you to alert them when you want to go to the toilet? No?

同样,浏览器会限制访客用户界面允许访问的信息。即使你找到了一个解决方法,因为浏览器并没有自愿放弃这些信息,这些聪明的黑客很脆弱,而且很可能成为常见的错误来源。

Similarly the browser limits what info the guest UI is allowed to access. Even if you found a workaround for the fact that browsers aren't giving up this info voluntarily, such clever hacks are fragile and likely to be constant source of bugs.

在任何代码被删除之前,应用程序最初可能是通过浏览器提供的,但问题在于首先包括要求。

Since its likely that the application was originally intended to be delivered via the browser before any code was cut, the fault lies with including the requirement in the first place.

我们所能做的一切你被要求执行一项几乎不可能的,当然也不是明智的要求,请同情你。

All we can do sympathise with you in being asked to perform an near impossible and certainly not sensible requirement.

这篇关于检测用户是否正在关闭IE浏览器而不是onunload事件,因为它在用户刷新等时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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