...

View Full Version : Window.Focus()



brixel
04-02-2005, 12:49 AM
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.

warhammerdude20
04-04-2005, 12:57 AM
2 things come to mind, Im assuming this is javascript...

1, you can constantly update the window every second:



blah=setInterval("window.focus();",1000);



or 2(I think this should work), wait for it to blur:




window.onblur="window.focus();";



Try it with and without the quotes... if 2 doesnt work, then use 1.

hope that helps

brixel
04-04-2005, 01:21 AM
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.

rlemon
04-08-2005, 04:38 PM
i dont know it this will work. or if this is even the correct syntax... but heres my guess.... :confused:

if(!window.focus() | !this.form.e.focus()){
do some code
}

brandonH
04-08-2005, 09:04 PM
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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum