user3911545
user3911545

Reputation: 309

capture "back button" Keypress in android with jquery

it is possible to capture the "back button" Keypress in Android with jquery?. I ve got a Close Button and I want to use the back button from my Android to close the modal window.

Can this be done without Java, only with JS or jQuery?

Thanks

Upvotes: 3

Views: 4165

Answers (1)

Eric Guan
Eric Guan

Reputation: 15982

You can detect it using the keycode

$(document).on('keydown', function(event) {
    if (event.keyCode == 27) {
      // Prevent default (disable the back button behavior)
      event.preventDefault();

      // Your code
    }
});

Upvotes: 1

Related Questions