Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-02-2005, 12:49 AM   PM User | #1
brixel
New to the CF scene

 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
brixel is an unknown quantity at this point
Window.Focus()

Hey guys,

I'm not sure if this is doable. I pop a window, and I want that window to maintain focus until the user closes it. I can keep the window in focus, but the problem is that it contains a form, and if the user starts filling out the form the window thinks it has lost focus, and tries to refocus itself.

This is bad because my drop downs clear out while a user is making a selection.

I've search a great deal, but can not seem to find a way to detect the status of a window's focus. It would be great if I could say:

if (window.isNotFocused) {
window.focus();
}

But no such property exists. How, or is there a way to do what I'm trying to do? Thanks.
brixel is offline   Reply With Quote
Old 04-04-2005, 12:57 AM   PM User | #2
warhammerdude20
Regular Coder

 
Join Date: Dec 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
warhammerdude20 is an unknown quantity at this point
2 things come to mind, Im assuming this is javascript...

1, you can constantly update the window every second:
Code:
blah=setInterval("window.focus();",1000);
or 2(I think this should work), wait for it to blur:

Code:
window.onblur="window.focus();";
Try it with and without the quotes... if 2 doesnt work, then use 1.

hope that helps
__________________
UNDER CONSTRUCTION
warhammerdude20 is offline   Reply With Quote
Old 04-04-2005, 01:21 AM   PM User | #3
brixel
New to the CF scene

 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
brixel is an unknown quantity at this point
Problem is that if you have a form in that window with lets say some drop downs, the page will "refresh" causing a users drop down to select itself if currently picked. Both methods you provided do this, when picking a form element it essentially "blurs" the window.
brixel is offline   Reply With Quote
Old 04-08-2005, 04:38 PM   PM User | #4
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
i dont know it this will work. or if this is even the correct syntax... but heres my guess....

if(!window.focus() | !this.form.e.focus()){
do some code
}
rlemon is offline   Reply With Quote
Old 04-08-2005, 09:04 PM   PM User | #5
brandonH
Regular Coder

 
Join Date: Oct 2003
Location: on a ship
Posts: 574
Thanks: 1
Thanked 6 Times in 5 Posts
brandonH is on a distinguished road
this should work!

ok where you are going wrong i think is trying to detect the windows focus!
instead set an id to the body tag like so:
<body id=body>

and then detect the body's focus!

I'd do it by setting an onblur detect in the body tag:

<body id=body onblur="ReFocus()">

as far as script, when the page loads set the focus to the body
because it doesnt start focused. once it has focus when ever it loses focus it'll focus on the window then focus on the body again.
hopefully by the body having focus all objects within it count as part of it!

put the following at the bottom of your source code.
reason is it'll cause an error if you try to set focus to the body before it is loaded, so you have to focus on it after it has loaded.

<script javascript>
document.getElementById('body').focus();
function ReFocus(){
window.focus();
document.getElementById('body').focus();
}
</script>
brandonH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:55 PM.


Advertisement
Log in to turn off these ads.