User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3 IE implements document.hasFocus which provides a reliable way to determine whether any element in the browser window has focus. Mozilla should have this too. Some browser applications will behave differently based on whether the page has focus. Reproducible: Always
I'm working on a new product that will have a lot of usage. This functionality is essential to it working well. Would be very happy to see this in FF1.1 so that the Firefox experience can be at least as good as the IE experience.
Created attachment 185720 [details] HTML file using document.hasFocus This was taken from http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/hasfocus.asp which exemplifies the use of document.hasFocus. It works on IE but doesn't work for me. Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
Created attachment 185723 [details] Workaround for missing hasFocus attribute This is the same file with a very simple modification that replaces document.hasFocus. Something a little more robust might be necessary for a decent workaround, but this works.
That workaround doesn't work if there are nested iframes in the page. If a nested iframe has focus, the workaround doesn't return the right value. In IE, document.hasFocus() returns true if anything nested in the document has focus, including content inside iframes.
Assignee: general → pkasting
Status: UNCONFIRMED → NEW
Ever confirmed: true
Created attachment 224139 [details] [diff] [review] patch v1 This seems to do the right thing as far as I can tell. Testcase files to be attached shortly.
Created attachment 224140 [details] Testcases Unzip this .tgz file somewhere. test.html is a simple test based on the test already attached to this bug. test1.html and test2.html are more complex tests that we get the proper behavior with nested iframes. In all cases, mousing over the "mouse over me" text should display a message iff that document or any children have focus.
I'd really prefer that someone more familiar with focus than I looked at this... but in any case, you need to change the IID of the interface and please add at the end, not in the middle?
OK, I can change it. The reason I didn't change it was because the last couple of additions to that file hadn't changed it, but maybe I was looking in the wrong place or something.
Created attachment 224142 [details] [diff] [review] patch v2 Address bzbarsky's comments.
This patch is included (in a slightly modified form) inside the patch I just attached to bug 337631, with the same reviewers.
Comment on attachment 224142 [details] [diff] [review] patch v2 removing this review since the patch is folded into bug 337631
Comment on attachment 224142 [details] [diff] [review] patch v2 In that case I'll remove the SR request as well.
FIXED by the commit of bug 337631 to the trunk.
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.