IE9 Window Loses Focus due to jQuery Mobile IE9 Window Loses Focus due to jQuery Mobile asp.net asp.net

IE9 Window Loses Focus due to jQuery Mobile


I know this is an old post, but for people coming here from Google:

I ran into this same issue today. It seems this lose focus behavior is what IE does when you trigger the blur event on the window object. This was the code that caused this issue for me:

$(document.activeElement).blur();

activeElement will default to the body element when there are no other elements in focus, and the blur event then bubbles up to the window. To fix this I simply did a check like:

if (document.activeElement != $('body')[0]) {    $(document.activeElement).blur();}


I had similar problem with IE10 and jQuery 1.7.2.I found these lines in my code:

$(document.activeElement).blur();

and

$(':focus').blur();

So, adding simple .not('body') resolves the problem:

$(document.activeElement).not('body').blur();$(':focus').not('body').blur();


This same issue seems to occur with jQuery Mobile 1.4.2.

When using IE 10, with a single tab open and another window on the same monitor, if you open a popup it will send the browser to the background.

To fix this you have to edit the _handleDocumentFocusIn function. You need to change the line(10391) that reads:

target.blur();

to

if (targetElement.nodeName.toLowerCase() !== "body"){    target.blur();}

I made a pull request so hopefully this will be included in the next version.