stopping key event bubbling in safari 4 windows

2019-07-16 10:48发布

问题:

In safari 4 windows, it does not seem possible to stop some key events from bubbling up to the browser in javascript.

This guy got pounced on for trying to stop F5 (a dubious design goal), but the technical problem remains... how do you stop certain key events from bubbling up in Safari 4? For example,

You can stop:

  • CTRL+T
  • CTRL+N

You cannot stop:

  • CTRL+F
  • F5

回答1:

Interesting. My tests gave the same results as yours: I couldn't find a way to prevent the default action of CTRL+F in Safari 4 in Windows, which suggests it's a deliberate design decision. However, I did discover the probably useless fact that putting an alert in my keydown event handler prevented the search bar from appearing, regardless of whether I then cancelled the event default action.