I have this:
$(window).bind("focus", function() {
$('input[name=myName]').focus();
});
But it was causing “too much recursion”. So I changed it to this:
$(window).one("focus", function() {
$('input[name=myName]').focus();
});
But that of course only works the first time the window gets the focus.
Q: How do I write it so that every time the user toggles to another screen and back to this one, then myName has the focus?
Prevent the event from bubbling by assigning a handler to the inputs that calls
e.stopPropagation():or just have your
windowfunction check thee.targetto see where the event came from:EDIT: Added quotation marks around the value part of the attribute selector. This is mandatory.