Click here to Skip to main content
16,020,990 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted

JavaScript
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:
JavaScript
<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 : 
http://stackoverflow.com/questions/4427714/confirm-dialog-when-i-close-the-browser[^]
 
Share this answer
 
v2
Check How to catch Alt+F4?[^].
It has two different types of answers for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900