开发者

Where is the focus going?

开发者 https://www.devze.com 2023-03-04 03:29 出处:网络
When an element on a page loses focus, the focus always goes somewhere else; the handler for the blur event receives an event object but I don\'t see anything 开发者_开发百科in there that tells me whe

When an element on a page loses focus, the focus always goes somewhere else; the handler for the blur event receives an event object but I don't see anything 开发者_开发百科in there that tells me where the focus is going.

How can I find that out?


You should have a look at: https://developer.mozilla.org/en/XUL_Tutorial/Focus_and_Selection

There's a section called 'Getting the currently focused element' which explains exactly how to achieve what you need, via the following code:

function init(){
  addEventListener("focus",setFocusedElement,true);
}

function setFocusedElement(){
  var focused = document.commandDispatcher.focusedElement;
  document.getElementById("focused").value = focused.tagName;
}

Good luck!


here's at least a partial answer: you can hook the /mousedown/ event, which bubbles up and which occurs before focus actually changes. if the user hits a tab instead of using the mouse, I don't know how it can be done!

0

精彩评论

暂无评论...
验证码 换一张
取 消