-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 13393: .focus() results in "Unspecified Error" in IE9 #1181
Conversation
I didn't add a check to run this for IE9 only or a check to make sure document.body.focus is a method. What do you think? |
It's good to know that the problem only occurs before the document is ready. My Spidey senses tingle when it comes to actively forcing focus to anything though. If we're nested a couple of iframes deep for example, is this going to cause an issue if the outer iframe monkeys with the focus as well? I wonder if we might be able to skip the I think the test should run on all browsers to make sure we didn't break them. On XML documents |
"is this going to cause an issue if the outer iframe monkeys with the focus as well?" "I wonder if we might be able to skip the document.activeElement check if the doc isn't ready and still get the focus to work." In case it's not possible to avoid the document.activeElement check I'll try to discard any outer iframe interaction with the current approach ( perhaps using this.ownerDocument.body.focus() instead and checking edge cases ). |
Thanks for looking at this. The focus/blur stuff tends to be really fidgety in both IE and Firefox. Another thought, maybe we could use the flag that @gibson042 is proposing in gh-1183 if focusing the body isn't reliable. We could avoid focusing the element if the document isn't ready but still run the handlers. Your solution is better but this could be a fallback. |
check |
Great! Sorry guys, busy week :( |
ping @timmywil on this ... should I close the PR or do you plan to riff off this? |
Yep, I'll poke @timmywil PR closed :) |
@timmywil what about having document.documentElement.activeElement as a fallback for document.activeElement? Please take a look at my last commit. Perhaps we could redefine the focus method after the first call when doc is ready to avoid any overhead, although I don't think is needed. Using document.documentElement.activeElement caused "focusin bubbles" tests to not pass and that's why I thought of the fallback approach. @dmethvin reopening the PR was the way I found to ping @timmywil :) |
@dgalvez : Thanks! This is already in the works. |
@timmywil cool! |
I couldn't find a better way to avoid IE9 crashing when evaluating document.activeElement. This patch sets documet.body as the activeElement in case elem.focus() is called before document.readyState !== "complete" and then redefines jQuery.event.special.focus.trigger to avoid re-running the extra check and body.focus() statements.
A test case has been added.
The bug url: http://bugs.jquery.com/ticket/13393