2

How I can call this method of the esc function, to stop page loading, with jquery. This is there some api call or something else. Anyone an idea?

EDIT:

I want to cancel a form submission.

What I am using now:

window.stop();

Thanks

4

2 回答 2

3
$(document).keydown(function(e) {
  if (e.which== 27) {  // ESC
    window.stop();
  }   
});

https://developer.mozilla.org/en-US/docs/Web/API/window.stop

The stop() method is exactly equivalent to clicking the stop button in the browser. Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading, but it will stop the loading of large images, new windows, and other objects whose loading is deferred.

PLAYGROUND

于 2013-05-22T12:00:25.577 回答
2

Here it is

$(document).keyup(function(e) {
    if (e.keyCode == 27) { alert('esc pressed'); }   // esc
});

The keyCode property return the key that was pressed so you just need the correct number in your case the Escape key is 27.

于 2013-05-22T11:59:02.967 回答