0

http://jsfiddle.net/Guruprasad_Rao/cezjbuky/

I have got the window.onbeforeunload event to prevent from closes like click on cross button on the browser or click on Ctrl + W.

How can I capture what the user has clicked on (whether user chose Leave This Page Or Stay on this Page)?

function warning(){
    if(true){


      return "You are leaving the page";
    }

}
window.onbeforeunload = warning;

function togooglepage()
{
    window.location = "www.google.co.in";
}

function toyahoopage()
{
    window.location = "www.yahoo.com";
}
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Pawan
  • 31,545
  • 102
  • 256
  • 434

1 Answers1

0

you can capture these events like that:

$(window).keydown(function(event) {
  if(event.ctrlKey && event.keyCode == 87) { 
    event.preventDefault(); 
  }
});

Here is a link for the Key Codes

for more information look at this answer.

Community
  • 1
  • 1
israel altar
  • 1,768
  • 1
  • 16
  • 24