当我们通过快捷键Alt + F4关闭时如何获取确认框 [英] how to get the confirmation box when we close by shortcut that is Alt+F4

查看:108
本文介绍了当我们通过快捷键Alt + F4关闭时如何获取确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用c#.net中的Alt + F4快捷键关闭应用程序时得到确认框,

I would like to get the confirmation box when we close the application by using Shortcut key that is Alt+F4 in c#.net can any one help

推荐答案

document.onkeydown = keydown; 
function keydown(evt)
{ 
  if (!evt) 
     evt = event;
  if (evt.altKey && evt.keyCode==115)
  { 
     // ALT+F4 
     alert("ALT+F4"); // Do whatever you want here
  } 
} 



相反,您也可以尝试以下脚本:



Instead you can also try below script:

<script>      
var userIsEditingSomething; // set this if something crazy happens         
oldOnBeforeUnload = window.onbeforeunload;      
window.onbeforeunload = function () 
{         // attempt to handle a previous onbeforeunload        
    if ('function' === typeof oldOnBeforeUnload) 
    {             
        var message = oldOnBeforeUnload();             
        if ('undefined' !== typeof message) 
        {                 
           if (confirm('string' === typeof message ? message : 'Are you sure you want to leave this page?'))    
           {   
               return; // allow user to exit 
           }
        }
    }         
    if (userIsEditingSomething) 
    {
                 return 'Are you sure you want to exit?';        
    }
};  </script>

I got this script from : 


检查如何捕捉Alt + F4? [
Check How to catch Alt+F4?[^].
It has two different types of answers for you.


这篇关于当我们通过快捷键Alt + F4关闭时如何获取确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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