简体   繁体   English

如何防止ESC按键断开连接?

[英]How to prevent connection break on ESC press?

When we press ESC, browser's server connection would break unless another request such as user input or ajax request. 当我们按ESC时,浏览器的服务器连接将中断,除非有其他请求(例如用户输入或Ajax请求)。

My problem is that when I press ESC while I am uploading the file into server, my upload do not process further(It hanged). 我的问题是,当我在将文件上传到服务器时按ESC时,我的上传没有进一步处理(挂起)。 But I need to press ESC for some feature of my page. 但是我需要按ESC键才能显示页面的某些功能。 Such as, 如,

  1. Pressing ENTER for rename and ESC for ignoring rename. 按ENTER键进行重命名,按ESC键忽略重命名。
  2. Pressing ESC to cancel the message box, etc. 按ESC取消消息框等。

How do I write JavaScript to prevent the breaking of connection when we press ESC. 我按ESC时如何编写JavaScript以防止断开连接。

Let the Two functions for ignoring rename and canceling message box be cancelRename(); 让忽略重命名和取消消息的两个函数框为cancelRename(); and cancelMsgBox(); cancelMsgBox(); Now check for ESC press on your browser by this script; 现在,通过此脚本在浏览器上检查是否按ESC;

function isESCpress(ev) {
if(ev.keyCode==27) {cancelRename();cancelMsgBox();return false;}
}
document.onkeypress=isESCpress;

Note: 注意:

Function cancelRename(); 函数cancelRename(); and cancelMsgBox(); cancelMsgBox(); will always called when you press ESC. 当您按ESC时将始终调用。 Thus you have to manage that yourself. 因此,您必须自己进行管理。

Hints: 提示:

function cancelRename() {
if(cancelStatus==1) //do your rename cancel process
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM