最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable reload and f5 on my php page - Stack Overflow

programmeradmin1浏览0评论

i am using a timer on my php page but when some refresh the page the timer start from begin. i want to disable f5 or reload option on my php page.

Thanks in advance

i am using a timer on my php page but when some refresh the page the timer start from begin. i want to disable f5 or reload option on my php page.

Thanks in advance

Share Improve this question edited Sep 10, 2013 at 18:43 Ankit Agrawal asked Mar 31, 2013 at 19:03 Ankit AgrawalAnkit Agrawal 6,1246 gold badges27 silver badges49 bronze badges 5
  • 3 That is not (and should not be) possible. – Maerlyn Commented Mar 31, 2013 at 19:05
  • so how can i prevent my timer to start from begining when my page is reload – Ankit Agrawal Commented Mar 31, 2013 at 19:14
  • Save the timer's state in onbeforeunload and restore it in onload. – Maerlyn Commented Mar 31, 2013 at 19:17
  • please provide me some example – Ankit Agrawal Commented Mar 31, 2013 at 19:19
  • at best you could maybe store the timer's current value in a cookie and check on each timer tick. but you can NOT prevent a user from reloading/refreshing a page in THEIR browser. – Marc B Commented Mar 31, 2013 at 19:42
Add a comment  | 

3 Answers 3

Reset to default 9

I test it and it works.

function disable_f5(e)
{
  if ((e.which || e.keyCode) == 116)
  {
      e.preventDefault();
  }
}

$(document).ready(function(){
    $(document).bind("keydown", disable_f5);    
});

Can't be done – that behaviour is controlled by the end user, and rightly so!

The nearest thing you can do is to display a warning when the window is closed or refreshed, which the user can either decide to heed your warning and stick with the current page, or ignore your request and close/refresh anyway.

See here: Alert when browser window closed accidentally

It is impossible to disable such browser functionality. Would you like it if a page disabled your F5 key? I doubt it. If you are trying to implement some kind of security here, I suggest looking at proper server-side verification approaches.

发布评论

评论列表(0)

  1. 暂无评论