Page 1 of 1

Focusing a Window using Javascript

Posted: Fri Dec 19, 2003 11:45 am
by igoy
This is a Genuine Problem.. situation is like this.

I've a flash animation made for client, which has a link which opens a window so that viewer fill a small HTML form. Now this animation runs fullscreen and I need to bring this form window in front of the animation.

I used focusing in onLoad event of HTML page...
<body onLoad="self.focus()">
it didn't worked...
then I tried focusing even a form field..
<script language="javascript">
<!--
function BringMeUp() {
self.focus();
document.all.fieldname.focus();
}
//-->
<body onLoad="BringMeUp()">
this also didn't worked....
I even tried using alert() thinking this will steal the focus.

I realized why this was happening, by default Window 98 and later (2000, XP) has a feature wherein user can disable windows stealing the focus, instead applications which requires focus start blinking or flashing in taskbar.

If I disable that everything works as charm, with enabled everything fails.

So the Question is ... ahem..

is there any way, by which I can forcefully steal the focus using Javascript ?

Posted: Sat Dec 20, 2003 7:18 am
by igoy
12 views and no answer.
Please guys, someone please answer !!!!

Posted: Sat Dec 20, 2003 8:47 am
by Gen-ik
You need to attach the window to a variable in JS when you open it. You can then focus the variable... sort of.

Code: Select all

<script language="javascript">

function openWindow()
&#123;
     theWindow = window.open("page.htm","","options etc");
&#125;

function focusWindow()
&#123;
     theWindow.focus();
&#125;

</script>
You don't need seperate functions though you can just do this..

Code: Select all

<script>

function openWindow()
&#123;
     theWindow = window.open(blabal);
     theWindow.focus();
&#125;
</script>
Hope that helps.

Posted: Sat Dec 20, 2003 9:15 am
by igoy
Thanks for your Help Gen-ik, but you see I'm opening this HTML page from Flash movie. This Flash movie is in Exe format and runs fullscreen. What I want is this HTML page should steal focus from Flash movie.

Please read the whole case I have written.

Still, I appriciate your efforts to Help me.

Posted: Sat Dec 20, 2003 10:34 am
by Gen-ik
In that case why not create a form within the actual Flash movie?

Posted: Sat Dec 20, 2003 10:44 am
by igoy
good question !!!

well, The form is pretty big.. almost 15-18 field, quite a number of drop-down lists, and need some real complex validations (across form fields).. then also there is disabling-enabling of form fields on choices of user.

All of this require pretty complex coding and time in Flash, when compared to doing in HTML & javascript.

and then there is the main point, for the budget client is looking at, he can only afford HTML form. ;)

Posted: Sat Dec 20, 2003 10:52 am
by Gen-ik
Oh ok, fair point.

Just a thought..... in the window that opens with the form in it you say you have tried using self.focus() to get it to appear in front of the Flash movie. Have you tried using window.self.focus() instead?

Posted: Sat Dec 20, 2003 11:13 am
by igoy
yes, I have :)

Posted: Mon Dec 22, 2003 4:09 am
by igoy
So I assume, there is no way you can steal focus from a window forcefully ???

Posted: Mon Dec 22, 2003 7:18 am
by Gen-ik
Having <body onload="window.self.focus()"> or <body onload="window.top.focus()"> in the window should focus it.

I don't know why it's not working for you though. It may or may not have something to do from the fact you are running Flash as a full-screen executable.... but I don't see why this should be stopping the window from focusing.

Posted: Mon Dec 22, 2003 7:48 am
by igoy
I understand that, Basically when you are using this kind of focusing in browsers it works. I mean, from one webapge to another.

what happening is here it's going from one application to another. That is, from Flash executable to Internet Explorer or any other browser.

As I had described in my post,
I realized why this was happening, by default Window 98 and later (2000, XP) has a feature wherein user can disable windows stealing the focus, instead applications which requires focus start blinking or flashing in taskbar.

If I disable that everything works as charm, with enabled everything fails.
What I'm trying to find, despite the feature enabled, is there any way we can steal focus, using Javascript.

Posted: Mon Dec 22, 2003 8:22 am
by igoy
Okay... here was one Advice from my Friend...

with onLoad event, use onLostFocus event handler to fire same Focus function.

and so far I tested on my system (WinXP with prevent Focusing enabled), and it seemed to work.

But I cudn't find onLostFocus handler in javascript documents I have, right now I'll be searching on Google. But if anyone have any idea about onLostFocus event handler and it's compatibility across browser. Please Post...

Posted: Mon Dec 22, 2003 8:30 am
by Gen-ik
I guess the onLostFocus command is the same as onblur.. I haven't heard of onLostFocus either and I use JS quite a lot.
You need to be careful that onLostFocus isn't an IE only command if you decide to use it. onblur is used within all browsers (as far as I know).

Posted: Mon Dec 22, 2003 8:30 am
by JayBird
isn't onLostFocus the same as onBlur.

Like you, i can't find much about the onLostFocus event.

Mark

Posted: Mon Dec 22, 2003 8:33 am
by igoy
yeh... it's supposed be like onBlur(), but cudn't find much about it.