jQuery Prevent Default Action Function Keys (F3, F

2019-02-20 03:18发布

I have this extremely basic example here: http://jsfiddle.net/arhVd/1/

<form>
  <input type="text">
  <input type="submit">
</form>

$(function () {

    $(document).keydown(function(e) {

        e.preventDefault();

        $('form').submit();
    });
});

I want to ensure that when pressing F4 it does not do the built in browser function (in F4's case set focus to the URL bar. Or perhaps F3 showing the 'Find' bar.) The functionality of submitting the form still works, I just don't want the browser functionality getting in the way.

This is for an internal app where the function keys are supposed to function has HotKeys in the app.

2条回答
姐就是有狂的资本
2楼-- · 2019-02-20 03:46

This seems to work for F3 in IE8:

$(document).keydown(function(event) {
  event.preventDefault();

  if (event.keyCode == 114) { // F3
    // Remap F3 to some other key that the browser doesn't care about
    event.originalEvent.keyCode = 0;
  }
};

(based on http://www.fixya.com/support/t218276-disable_f3_function_key_from_intenet)

查看更多
疯言疯语
3楼-- · 2019-02-20 03:56

I don't believe you can hi-jack the user's browser.

查看更多
登录 后发表回答