如何区分浏览器关闭事件和刷新事件? [英] How to differentiate between browser close event and refresh event?

查看:494
本文介绍了如何区分浏览器关闭事件和刷新事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何区分浏览器关闭事件和
浏览器刷新事件(使用图标和F5键)?

解决方案

简短回答,您无法做到,因为这两个事件都不是单个定义的事件". br/> 例如,当浏览器关闭但会触发onUnload事件,但当您离开页面导航时也会调用onUnload事件,因此不合适. ..但我正在尝试是否有确定的东西我会为您发布


这是该解决方案的
如果由于控件上的操作而发生回发,则document.getElementByID(''__ EVENTTARGET'')将不为null.因此,使用此隐藏字段,您可以知道wich control在页面中触发了回发.

否则,如果这是正常刷新,则此值将始终为null.

因此,您可以在CodeBehind中检查此值以了解.

希望对您有帮助


How can we distinguish between browser close events and
browser refresh events (using icon and F5 key)?

解决方案

Short answer, you can''t as neither one is a single defined ''event''.
For example the onUnload event will be raised when the browser closes BUT it is also called when you navigate away from the page, so not suitable.


i am gone almost everything to search this but failed .. but i am trying if got anything surely i will post it for you


Here is a solution for that
if there is a postback due to an action on the control, document.getElementByID(''__EVENTTARGET'') will not be null. So using this hidden field you can know wich control fired the postback in the page.

Else if this a normal refresh then this value will be null always.

So you can check this value in the CodeBehind to know.

Hope this will help you


这篇关于如何区分浏览器关闭事件和刷新事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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