Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Cannot regain keyboard focus after closing childwindow (Firefox)...

Reply
Thread Tools

Cannot regain keyboard focus after closing childwindow (Firefox)...

 
 
drupel
Guest
Posts: n/a
 
      12-27-2005
Simple task:
A main window opens a "child" window.
Both windows have keydown handlers.
Main window opens child window on enter key.
Child window closes itself on enter key.

After the child window closes, the main window has lost keyboard focus,
meaning that it does not respond to keydown events anymore.

Installed a timer that checks periodically if child window is closed.
Setting focus back to main window in this timer did not succeed.
Tried self.focus() and window.focus().

Any suggestions?

Greetings,
drupel

Sample code follows:

----x---- window-opener.html begin ----x----
<html>
<head>
<title>window opener</title>
<script>
function log_writeln() {}

function test(e) {
// access event data
if( typeof( e ) == 'undefined' ) {
e = window.event;
if( typeof( e ) == 'undefined' ) {
alert( "e undefined" );
return;
}
}

var key;
// access key code
if( e.keyCode ) {
key = e.keyCode;
} else
if( e.which ) {
key = e.which;
} else {
log_writeln( "key undefined" );
return;
}

log_writeln( "key : " + key );
if( 13 == key ) {
enter();
window.setTimeout( "gainFocus()", 50 );
}
} /// method

var childWindow = null;
function enter() {
if( null != childWindow ) {
return;
}

childWindow = window.open( "/test/open-window.html",
"open_window", "width=100px, height=100px" );
} /// method

function gainFocus() {
log_writeln( "gain focus enter" );
if( null != childWindow && childWindow.closed ) {
//window.focus();
self.focus();
childWindow = null;
log_writeln( "gain focus OK" );
} else {
log_writeln( "gain focus trying" );
window.setTimeout( "gainFocus()", 50 );
}
} /// method
</script>
</head>
<body onkeydown="test(event);">
</body>
</html>
----x---- window-opener.html end ----x----

----x---- open-window.html begin ----x----
<html>
<head>
<title>open-window</title>
<script>
function test(e) {
// access event data
if( typeof( e ) == 'undefined' ) {
e = window.event;
if( typeof( e ) == 'undefined' ) {
alert( "e undefined" );
return;
}
}

var key;
// access key code
if( e.keyCode ) {
key = e.keyCode;
} else
if( e.which ) {
key = e.which;
} else {
alert( "key undefined" );
return;
}

if( 13 == key ) {
window.close();
} else {
alert( key );
}
}
</script>
</head>
<body onkeydown="test( event );">
</body>
</html>

----x---- open-window.html end ----x----


 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      12-27-2005
drupel said:
>
>Simple task:
>A main window opens a "child" window.
>Both windows have keydown handlers.
>Main window opens child window on enter key.
>Child window closes itself on enter key.


Don't use the keydown event to do things that move the focus.
Why not onclick?

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nikon D40 cannot focus to infinity with manual focus prime lens zc94123@yahoo.com Digital Photography 8 08-17-2007 02:19 PM
FAQ Topic - How do I check to see if a childwindow is open, before opening another? FAQ server Javascript 4 04-25-2007 10:01 AM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
I can't regain control of my form Piccolo Pete C++ 9 04-08-2006 01:54 PM
Closing the doors 15 minutes before closing. doofus Computer Support 12 06-11-2005 08:20 AM



Advertisments