简体   繁体   中英

any way to catch a page-refresh and pause it?

Is there any way to catch a page refresh and pause it for a certain time period using javascript, jquery or whatever?

This is necessary to prevent accidentally pressing the refresh key amid an important work which is one-time ,and needs to be processed and saved before the page gets refreshed.

In one of my previous questions posted in this forum, I had to face this issue, which is still unsolved, at a certain point during the discussion of the question. I think posting it as an individual question is quite worth it. The said question is here .Edit part of the question contains the issue.

Scripting language is php. Or should I use any other language to achieve the goal?

It appears this can be accomplished with window.onbeforeunload() like in this example .

<script type="text/javascript">
   window.onbeforeunload = function() {
       return "You sure you want to leave? You will lose all your work!";
   }
</script>

我认为您应该使用:

<body onbeforeunload="return 'are you sure you want to move away from this page?';">

I don't think there is a way to stop or pause the page refresh. Yes, you can give a warning, but to be safe you just fill user's cookie with current state of form's input fields with javascript at every form field change. User pressed radiobutton? Cookies updated. User updated input field? Cookies updated.

Then, on page load, just have php or javascript read cookies and fill the form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM