JavaScript - 如何告诉浏览器Chrome,Firefox,Safari,允许我禁用刷新按钮? [英] JavaScript - How can i tell Browser Chrome, Firefox, Safari, to allow me to have the refresh button disabled?

查看:187
本文介绍了JavaScript - 如何告诉浏览器Chrome,Firefox,Safari,允许我禁用刷新按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有逻辑应用程序正在运行,我需要存储 var algorithmToApply = 1或者等等;

我的每个值都分配了相关算法。主要问题是测试用户点击浏览器刷新按钮和所有应用程序逻辑崩溃。

  algorithmToApply = 1; //思考
algorithmToApply = 2; //等待
algorithmToApply = 11; //下载
algorithmToApply = 100; //引导
algorithmToApply = 900; //内核准备
algorithmToApply = 0; //用户刷新按钮是一个BUG

如何使用JavaScript请求浏览器(Opera或Chrome可选Firefox / Safari),允许我限制用户无法点击刷新(但它们总是可以关闭或关闭我的浏览器实例)。



这可能吗?如果是这样,怎么样?



后续行动(最好我们可以做)

<$ p (b)('beforeunload',function(e){
if(mystatus> = 2))$ b $(window).bind {
return警告:您的状态是....如果您现在刷新,软件将失去所有状态。;
}其他{
返回警告:您的状态不是。 ..你可以刷新。;
}
});


解决方案

不可能。



然而,您可以添加一个 beforeunload 侦听器,它会提示您确认:

  var algorithmToApply = 0; 
window.onbeforeunload = function(){
if(algorithmToApply!== 0){/ * Anything .. * /
return'任务正在处理中。你真的想离开吗?';
}
};


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.";
  }      
});

解决方案

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

这篇关于JavaScript - 如何告诉浏览器Chrome,Firefox,Safari,允许我禁用刷新按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆