Prevent the event bubble by assigning a handler to the inputs calling e.stopPropagation():
$(window).bind("focus", function() {
$('input[name="myName"]').focus();
});
$('input[name="myName"]').focus(function(e) {
e.stopPropagation();
});
or just try the windowcheck function e.targetto find out where the event came from:
$(window).bind("focus", function(e) {
if( e.target === window ) {
$('input[name="myName"]').focus();
}
});
EDIT: Added quotation marks around the value part of the attribute selector. It is necessary.
source
share