JavaScript - How can i tell Browser Chrome, Firefox, Safari, to allow me to have the refresh button disabled?

南笙酒味 提交于 2019-11-30 09:47:24

问题


I have logical application running where i need to store the var algorithmToApply=1 or etc;

Where each of my value has relative algorithm assigned. The main problem is while testing people clicking on browser refresh button and all my application logic crash.

algorithmToApply = 1 ; // Thinking
algorithmToApply = 2 ; // Waiting
algorithmToApply = 11 ; // Downloading
algorithmToApply = 100 ; // Booting
algorithmToApply = 900 ; // Kernel prepare
algorithmToApply = 0 ; // User refresh button is a BUG

How can i using JavaScript request Browsers (Opera or Chrome optionally Firefox/Safari), to allow me to restrict user not able to click refresh (however they can always shutdown or close my browser instance).

Is this possible? If so how?

Follow up: (best we can do )

/* @WARNING: Do not refresh */
$(window).bind('beforeunload', function(e) {  
  if (mystatus>=2) {
   return "WARNING: Your status is .... If you refresh now, software will lose all the status.";
  } else {
   return "WARNING: Your status is not ... You can refresh.";
  }      
});

回答1:


That is not possible.

You can, however, add a beforeunload listener which prompts for confirmation:

var algorithmToApply = 0;
window.onbeforeunload = function() {
    if (algorithmToApply !== 0) { /* Anything ..*/
        return 'A task is pending. Do you really want to leave?';
    }
};


来源:https://stackoverflow.com/questions/9727344/javascript-how-can-i-tell-browser-chrome-firefox-safari-to-allow-me-to-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!