检测F5是pressed和刷新 [英] Detect F5 being pressed and Refresh
问题描述
我有一个WebForm,我想检测是否F5按钮被pressed或者如果页面刷新。我知道回发,但它不是我要找的。我有一个按钮被点击和参数的值设置为GridView时加载的模式弹出一个gridview。刷新时被击中,如果模式弹出按钮是previously点击的模式弹出是刷新后的可见光右。我想检测是否刷新页面,以prevent这一点。有任何想法吗?我想尝试覆盖,但我不完全知道如何使用它。我试过Control.ModifierKeys,但我没有访问ModifierKeys。
I have a webform and i want to detect if F5 button was pressed or if the page was refreshed. I know about postback but it is not what i'm looking for. I have a gridview that loads in a modal popup when a button is clicked and a parameter's value is set for the gridview. When refresh is hit and if the modal popup button was previously clicked the modal popup is visible right after refresh. I want to detect if the page is refreshed to prevent this. any ideas? I thought to try Override but I'm not exactly sure how to use it. I tried Control.ModifierKeys but I don't have access to ModifierKeys.
推荐答案
pressing F5或物理点击浏览器刷新行为会类似于导航离开页面。这是在事件window.onunload捕获。尝试下面的片段例如:
Pressing F5 or physically clicking the browser refresh behaves similarly to navigating away from the page. This is captured in the event window.onunload. Try the snippet example below:
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
这将捕获的刷新,让你做某件事,或者提示用户。
This will capture the refresh and allow you to do something or prompt the user.
这篇关于检测F5是pressed和刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!