Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
868 views
in Technique[技术] by (71.8m points)

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

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.";
  }      
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?';
    }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...