Lack of window.focus()

127 views
Skip to first unread message

Kerby Seeley

unread,
Jan 27, 2015, 2:16:04 PM1/27/15
to mi...@dartlang.org
My gut is telling me that the reason the Dart Window object is missing the focus() method is the spotty browser support, but I can't find a good official explanation.  Can anybody point one out, or provide a more specific answer?  I was able to work around the missing functionality by using JS context in my project, I'm mostly just curious.

Thanks

Vijay Menon

unread,
Jan 28, 2015, 4:25:27 PM1/28/15
to General Dart Discussion
This method was actually explicitly removed in Dart based on some early feedback.  The justification (from: http://www.w3.org/html/wg/drafts/html/master/editing.html#introduction-4):

The focus() method on the Window object, when invoked, must run the focusing steps with the Window object's browsing context. Additionally, if this browsing context is a top-level browsing context, user agents are encouraged to trigger some sort of notification to indicate to the user that the page is attempting to gain focus.

The blur() method on the Window object, when invoked, provides a hint to the user agent that the script believes the user probably is not currently interested in the contents of the browsing context of the Window object on which the method was invoked, but that the contents might become interesting again in the future.

User agents are encouraged to ignore calls to this blur() method entirely.

Historically, the focus() and blur() methods actually affected the system-level focus of the system widget (e.g. tab or window) that contained the browsing context, but hostile sites widely abuse this behavior to the user's detriment.



On Tue, Jan 27, 2015 at 11:16 AM, Kerby Seeley <kerby....@workiva.com> wrote:
My gut is telling me that the reason the Dart Window object is missing the focus() method is the spotty browser support, but I can't find a good official explanation.  Can anybody point one out, or provide a more specific answer?  I was able to work around the missing functionality by using JS context in my project, I'm mostly just curious.

Thanks

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

David Notik

unread,
Mar 21, 2015, 2:16:30 AM3/21/15
to mi...@dartlang.org
This was helpful. But, how then does one return focus to the app when a desktop/web notification (https://developer.mozilla.org/en-US/docs/Web/API/Notification/Using_Web_Notifications) is clicked? Isn't that the point of web notifications after all?

Alan Knight

unread,
Mar 23, 2015, 3:47:56 PM3/23/15
to mi...@dartlang.org
It seems like this might be useful. Created https://code.google.com/p/dart/issues/detail?id=22960

In the meantime, the usual workaround is that you can call it via JS interop.

David Notik

unread,
Mar 24, 2015, 2:20:14 PM3/24/15
to mi...@dartlang.org
notificationClicked(Event e) => context.callMethod('focus');

FTW! Thank you.



Reply all
Reply to author
Forward
0 new messages