问题
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