By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

window.focus() brings source code into focus

P: n/a
I'm trying to figure out a workaround to a minor annoyance that I'm
coming up with while coding a site. I've got some keyboard shortcuts
set up for the site via javascript, and when I press escape, it's set
to hide several divs on the page, and remove focus from a link.
Unfortunately, I don't know which link will have focus, so I can't
just blur a particular element (that I'm aware of) since I won't know
which element it is. I got it working by using window.blur() followed
by window.focus(). The problem is that if I have a source code window
open, the window.focus() function brings the source code on top of
everything else and it takes focus. I don't see this being a huge
issue for users, but it's a real pain while I'm developing the site.
Does anyone know why it does this, and, more importantly, a workaround
for it?
Thanks in advance.
Jan 8 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Spizzat2 said the following on 1/8/2008 9:02 AM:
I'm trying to figure out a workaround to a minor annoyance that I'm
coming up with while coding a site. I've got some keyboard shortcuts
set up for the site via javascript, and when I press escape, it's set
to hide several divs on the page, and remove focus from a link.
Unfortunately, I don't know which link will have focus, so I can't
just blur a particular element (that I'm aware of) since I won't know
which element it is. I got it working by using window.blur() followed
by window.focus(). The problem is that if I have a source code window
open, the window.focus() function brings the source code on top of
everything else and it takes focus. I don't see this being a huge
issue for users, but it's a real pain while I'm developing the site.
Does anyone know why it does this, and, more importantly, a workaround
for it?
Thanks in advance.
When you blur the window, in Windows, it will go to the next application
in the active list. Alt-Tab and you will find your source window the
next "in line". It isn't explicitly picking the source code window to go
to, it just happens to be the next in line.

Try focusing an element in the page and then blur that element instead
of the window.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 8 '08 #2

P: n/a
On Jan 8, 1:20 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Spizzat2 said the following on 1/8/2008 9:02 AM:
I'm trying to figure out a workaround to a minor annoyance that I'm
coming up with while coding a site. I've got some keyboard shortcuts
set up for the site via javascript, and when I press escape, it's set
to hide several divs on the page, and remove focus from a link.
Unfortunately, I don't know which link will have focus, so I can't
just blur a particular element (that I'm aware of) since I won't know
which element it is. I got it working by using window.blur() followed
by window.focus(). The problem is that if I have a source code window
open, the window.focus() function brings the source code on top of
everything else and it takes focus. I don't see this being a huge
issue for users, but it's a real pain while I'm developing the site.
Does anyone know why it does this, and, more importantly, a workaround
for it?
Thanks in advance.

When you blur the window, in Windows, it will go to the next application
in the active list. Alt-Tab and you will find your source window the
next "in line". It isn't explicitly picking the source code window to go
to, it just happens to be the next in line.

Try focusing an element in the page and then blur that element instead
of the window.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
It still brings up the source code window regardless of source code's
position in the Alt-Tab list, but thanks for the potential solution.
I'll give it a shot and see how it works for my situation.
Jan 9 '08 #3

P: n/a
On Jan 9, 9:27 am, Spizzat2 <Spizz...@gmail.comwrote:
On Jan 8, 1:20 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Spizzat2 said the following on 1/8/2008 9:02 AM:
I'm trying to figure out a workaround to a minor annoyance that I'm
coming up with while coding a site. I've got some keyboard shortcuts
set up for the site via javascript, and when I press escape, it's set
to hide several divs on the page, and remove focus from a link.
Unfortunately, I don't know which link will have focus, so I can't
just blur a particular element (that I'm aware of) since I won't know
which element it is. I got it working by using window.blur() followed
by window.focus(). The problem is that if I have a source code window
open, the window.focus() function brings the source code on top of
everything else and it takes focus. I don't see this being a huge
issue for users, but it's a real pain while I'm developing the site.
Does anyone know why it does this, and, more importantly, a workaround
for it?
Thanks in advance.
When you blur the window, in Windows, it will go to the next application
in the active list. Alt-Tab and you will find your source window the
next "in line". It isn't explicitly picking the source code window to go
to, it just happens to be the next in line.
Try focusing an element in the page and then blur that element instead
of the window.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

It still brings up the source code window regardless of source code's
position in the Alt-Tab list, but thanks for the potential solution.
I'll give it a shot and see how it works for my situation.
Well, I got a solution that works using your method, so thank you for
that. I'm still confused about the cause of the problem, though. I
wonder if the source code page is considered a child window of the
parent, so when it brings it into focus, it just grabs the child-most
window (if that makes any sense).
Oh well, it works. I'm happy.
Jan 9 '08 #4

P: n/a
Spizzat2 said the following on 1/9/2008 10:45 AM:
On Jan 9, 9:27 am, Spizzat2 <Spizz...@gmail.comwrote:
>On Jan 8, 1:20 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>>Spizzat2 said the following on 1/8/2008 9:02 AM:
I'm trying to figure out a workaround to a minor annoyance that I'm
coming up with while coding a site. I've got some keyboard shortcuts
set up for the site via javascript, and when I press escape, it's set
to hide several divs on the page, and remove focus from a link.
Unfortunately, I don't know which link will have focus, so I can't
just blur a particular element (that I'm aware of) since I won't know
which element it is. I got it working by using window.blur() followed
by window.focus(). The problem is that if I have a source code window
open, the window.focus() function brings the source code on top of
everything else and it takes focus. I don't see this being a huge
issue for users, but it's a real pain while I'm developing the site.
Does anyone know why it does this, and, more importantly, a workaround
for it?
Thanks in advance.
When you blur the window, in Windows, it will go to the next application
in the active list. Alt-Tab and you will find your source window the
next "in line". It isn't explicitly picking the source code window to go
to, it just happens to be the next in line.
Try focusing an element in the page and then blur that element instead
of the window.
It still brings up the source code window regardless of source code's
position in the Alt-Tab list, but thanks for the potential solution.
I'll give it a shot and see how it works for my situation.

Well, I got a solution that works using your method, so thank you for
that. I'm still confused about the cause of the problem, though.
When you say "Source code window", are you referring to Notepad or some
other app that you use, or, an editing product where you preview it in
the program and then you can use the source code window?

I wonder if the source code page is considered a child window of the
parent, so when it brings it into focus, it just grabs the child-most
window (if that makes any sense).
Oh well, it works. I'm happy.
It could very well be that it is simply focusing the last window to have
focus before the current one. What an OS does when you blur a window is
up to the OS and not a lot that MS does makes any sense.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 9 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.