Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

window.document.onblur=function() {window.focus();}; not working

4,184 views
Skip to first unread message

Flintstone

unread,
Jun 13, 2008, 7:13:08 PM6/13/08
to
Can anybody understand why the following code does not work? It should
refocus the window whenever it loses focus. I do have the advanced JS
setting 'Allow scripts to Raise or Lower Windows' checked.

It should not be modal but it should stay focused regardless of what
happens in the main window (I set a timeout to remove the onblur event
after 10 seconds)..

<html>
<head>
<script language="JavaScript">
window.document.onblur=function() {window.focus();};
</script>
</head>
<body>
Lorem Ipsum
</body>
</html>

Flintstone

unread,
Jun 16, 2008, 4:13:03 AM6/16/08
to
So nobody appears to know why?
Message has been deleted

Flintstone

unread,
Jun 16, 2008, 9:08:13 AM6/16/08
to
A little more info:

window.document.onblur=function() {alert('Blurred');}; produces an
alert saying 'Blurred' when the window loses focus, this shows that
the event is triggered.

Typing window.onblur() in Firebug does bring the window into focus.

Does anybody have any other ideas?

Ralph Fox

unread,
Jun 17, 2008, 6:06:13 AM6/17/08
to
On Fri, 13 Jun 2008 16:13:08 -0700 (PDT), in message <68dd8da7-c508-4ee1...@2g2000hsn.googlegroups.com>,
Flintstone wrote:

> X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
^^^^^^^

> Can anybody understand why the following code does not work?

> window.document.onblur=function() {window.focus();};


It appears that you are trying to do something which your
underlying OS does not support (and which well-written
applications for your OS should refuse to do)...

http://msdn.microsoft.com/en-us/library/ms646282(VS.85).aspx

| WM_KILLFOCUS Notification
|
| The WM_KILLFOCUS message is sent to a window immediately before it
| loses the keyboard focus.
...
| While processing this message, do not make any function calls that
| display or activate a window. This causes the thread to yield
| control and can cause the application to stop responding to
| messages. For more information, see Message Deadlocks.


--
Cheers,
Ralph

Flintstone

unread,
Jun 17, 2008, 7:39:21 AM6/17/08
to
If this was the case then setTimeout would have fixed the problem but
it does not. Also, if the OS did not support this it would not work in
any other browser but it works fine in IE, Safari and Opera.

Ralph Fox

unread,
Jun 18, 2008, 6:06:28 AM6/18/08
to
Have you checked whether window.focus() is not working, only when used
with window.document.onblur, or whether it is not working also when
there is no reference to window.document.onblur. There is a user setting
which disables window.focus() - Allow scripts to: [ ] Raise or lower
windows

Flintstone

unread,
Jun 30, 2008, 6:09:56 AM6/30/08
to
As far as I can see windows are not able to focus themselves. The
config option to Allow scripts to: [ ] Raise or lower windows does not
appear to make a difference.

This is an issue for us because of Disabled (Section 508) users. Our
Web App windows need to be able to focus themselves under various
circumstances. This allows blind users etc much easier access to all
of our app windows because screen readers will have access to the
currently focussed window.

IF the Raise or lower windows option is allowed then we can attempt to
spawn a new popup with the same handle and it will refocus the window
but because this is an accessibility feature surely the Raise or lower
windows option should be allowed by default ... it actually makes the
browser more useable.

Ralph Fox

unread,
Jul 1, 2008, 5:00:21 AM7/1/08
to
On Mon, 30 Jun 2008 03:09:56 -0700 (PDT), in message <43751317-759c-45af...@b1g2000hsg.googlegroups.com>,
Flintstone wrote:

> As far as I can see windows are not able to focus themselves. The
> config option to Allow scripts to: [ ] Raise or lower windows does not
> appear to make a difference.

In my testing on WinXP, it does make a difference...

A. I find that window.focus() will raise a Firefox window above
other Firefox windows.

B. If another Firefox window has focus, then this Firefox window
gets focus.

C. If a different application has focus, then it does not take the
focus away from that other application (although the Firefox
window is still raised above other Firefox windows).


> This is an issue for us because of Disabled (Section 508) users. Our
> Web App windows

Do I understand it that your scenario has multiple browser windows,
rather than one browser window vs other applications' windows?


> need to be able to focus themselves under various
> circumstances. This allows blind users etc much easier access to all
> of our app windows because screen readers will have access to the
> currently focussed window.

--
Cheers,
Ralph

libra...@gmail.com

unread,
Feb 6, 2014, 3:25:23 PM2/6/14
to
Try this. It works fine because window.alert() gives the focus to the window and stop events propagation.

window.onblur = function (ev) { window.alert("Modal window"); }

Google should sove this problem.

Jo Smith

unread,
Feb 6, 2014, 4:20:45 PM2/6/14
to Firefox help community
Oh Thank You so Very Much! I will try..... I have tried everything else. Jo
> _______________________________________________
> support-firefox mailing list
> support...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/support-firefox
> To unsubscribe, send an email to
> support-fir...@lists.mozilla.org?subject=unsubscribe
>
0 new messages