Forum Moderators: open
I have an <input> with some special behaviour onblur. It does a little client-side validation and injects an error message into the form if the value is invalid.
It's really sweet when you tab from one field to another, or blur the field by clicking around the page.
However the event also fires when I do an Alt-Tab to another window. When I return to the page, I'm still focused on the same <input>, and I didn't really intend to blur it.
Is there a way to prevent that?
What I want is a way to distinguish between a blur() event happening on an HTMLElement, and the blur() of the entire window.
If the latter, you can always use
onblur on the page to set a variable; a variable you then check for when the element blurs (and use as an exception). When the page regains focus, use onfocus to reset the condition. If the other way around -- there is no way to distinguish between the two (blur of element vs blur of page, as one way or the other, the element blurred anyway). But, you can still use an
onblur event on the page itself to undo what the blurred input element triggered. In other words -- you cannot distinguish between the two. But you can work around it.