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
  • 40,889
  • 58
  • 100
  • 149
Pawan
  • 29,827
  • 94
  • 242
  • 415

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,745
  • 1
  • 15
  • 24