简体   繁体   English

退出键停止加载Web应用程序

[英]Escape key stops loading the web application

Hi we are facing the problem with escape key in our web application. 嗨,我们在我们的Web应用程序中面临着转义键的问题。 If user press the escape key the web application gets stop loading. 如果用户按退出键,则Web应用程序将停止加载。 I tried using all these with(onkeydown and onkeyup) 我尝试将所有这些与(onkeydown和onkeyup)一起使用

document.attachEvent("onkeydown", win_onkeydown_handler);
window.attachEvent("onkeydown", win_onkeydown_handler);
window.document.attachEvent("onkeydown", win_onkeydown_handler);

I cant able detect the escape( KeyCode=27 ) in my web application .. but i am able to detect refresh,f5 and all other keys 我无法在我的Web应用程序中检测到转义( KeyCode = 27 )..但是我能够检测到refresh,f5和所有其他键

Note: i face this problem in IE 注意:我在IE中遇到这个问题

This helps me to prevent escape in iframe 这可以帮助我防止在iframe中逃脱

function disableEscapeAndRefresh(){
try{
    if(window.frames && window.frames[0]){
        window.frames[0].focus();
        for (var i_tem = 0; i_tem < window.frames.length; i_tem++){
            if(document.all && document.body.filters)
                window.frames[i_tem].document.onkeydown = new Function("var e=window.frames["+i_tem+"].event; if(e.keyCode==116){e.keyCode=0;alert('Refresh Not Allowed');return false;}if(e.keyCode==27){e.keyCode=0;alert('Escape Not Allowed');return false;};");
        }
    }
}catch(e){

}
}

call this method in iframe onload 在iframe onload中调用此方法

我认为没有任何办法可以捕获它……这等效于单击X来停止页面加载。

Assuming that you are targeting versions of IE that have attachEvent enabled, you can use this to detect the escape key being pressed. 假设您的目标是启用了attachEvent的IE版本,则可以使用它来检测按下的转义键。 The handling of the event is the usual code for preventing default event behaviour, though this may not work on cancelling the page download as this may be seen as a security flaw (imagine the unscrupulous developer that wants to prevent the user from cancelling a malicious download): 事件的处理是用于防止默认事件行为的常用代码,尽管这可能无法取消页面下载,因为这可能被视为安全缺陷(想象一下不道德的开发人员希望阻止用户取消恶意下载):

document.attachEvent('onkeydown', function(){
  if(window.event.keyCode == 27) {
    window.event.returnValue = false; 
    window.event.cancelBubble = true;
  }
});

http://jsfiddle.net/steveukx/LJHs8/ http://jsfiddle.net/steveukx/LJHs8/

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

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