2

How can I catch the F5 key press when the mouse is outside my page?

For example hovering on a scroll bar, or on an address bar, or on a menu etc.

Because in this case e.which, which usually contains 116 for F5, contains undefined

EDIT: After playing with Alexey Lebedev' jsfiddle I discovered that if the last user click was inside my page, I actually can catch F5.

However if the last user click was outside my page, the problem remains.

I would think the browser client area is not in focus, but then it should not get the keypress and should not be refreshed at all.

4

1 回答 1

0

如果最后一次用户点击在您的页面之外,例如在地址栏中,刷新页面可能仍然是一个好主意F5,但该页面不应该能够窥探您正在输入的 URL,因此不应该t 接收键盘事件。

如果您的目标是防止在刷新时丢失未保存的数据,您可以在beforeunload.

于 2013-04-21T14:13:31.613 回答