Focusing a Window using Javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Focusing a Window using Javascript

Post 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 ?
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

12 views and no answer.
Please guys, someone please answer !!!!
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

In that case why not create a form within the actual Flash movie?
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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. ;)
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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?
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

yes, I have :)
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

So I assume, there is no way you can steal focus from a window forcefully ???
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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...
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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).
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

isn't onLostFocus the same as onBlur.

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

Mark
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

yeh... it's supposed be like onBlur(), but cudn't find much about it.
Post Reply