/    Sign up×
Community /Pin to ProfileBookmark

firefox3: window.focus() and blur() between tabs not working

Hello All,

I’m trying to build a data navigation utility that will allow a central “map” page to control a
number of tab pages that are loading individual pages from a large set of HTML.
All are local file://localhost/, with localhost popups enabled.
(for dev/testing all popups are enabled since firebug 1.3.3 has problems loading localhost
.js code)
preference to “raise and lower windows” has been enabled
I am using firefox 3.0.8 on FreeBSD 6.4

Anyway, I can’t get window.focus() and blur() to work between cooperating tab/windows
who know each other’s names.

Here following are two cooperating mirror tab pages that i’m trying to get working.
Have tried a number of combinations of the focus() and blur() calls.
Have tried with/without messaging. Messaging works fine.

I have noticed that the calling tab seems to unload/reload as a result
of the click event. This still allows the message to get through OK,
but I guess the reload could be taking the focus again.

An annoying alert() dialog could of course get focus to the message receiver,
but it requires another click to get it out of the way.

The concept of these focus() and blur() calls is so simple, and I’ve searched all
over the web for examples, but nothing seems applicable.

Have also seen that this may be a bug in Firefox.

Can anyone help me figure out what’s happening and the right sequence
to make these calls work ?

======== code for “mirror” pages “focus1” and “focus2” follows:

<html>
<head>
<title>test window focus – 1</title>
<script language=”javascript”>
var co_win2;
var co_name2 = “focus2”;
function init_it() {
window.name = “focus1”;
window.addEventListener(“message”, rcv, false);
}

function n() {
// alert( “click on FCS1” );
if( ! ( co_win2 && ! co_win2.closed ) ) { // reopen window
co_win2 = open( “”, co_name2, “” );
}
window.focus();
window.blur();
co_win2.postMessage( “go”, “*” );
//co_win2.focus();
event.stopPropagation();
event.preventDefault();
}

function rcv(evm) {
console.log( “1 received from 2” );
window.blur();
window.focus();
}

</script></head><body onload=”javascript: init_it()”>
<a id=”FCS1″ href=”” onclick=”n()”>Focus other window</a>

</body></html>

================ focus2:

<html>
<head>
<title>test window focus – 2</title>
<script language=”javascript”>
var co_win1;
var co_name1 = “focus1”;
function init_it() {
window.name = “focus2”;
window.addEventListener(“message”, rcv, false);
}

function n() {
// alert( “click on FCS2” );
if( ! ( co_win1 && ! co_win1.closed ) ) { // reopen window
co_win1 = open( “”, co_name1, “” );
}
window.focus();
window.blur();
//co_win1.focus();
co_win1.postMessage( “go”, “*” );
event.stopPropagation();
event.preventDefault();
}

function rcv(evm) {
console.log( “2 received from 1” );
window.blur();
window.focus();
}

</script></head><body onload=”javascript: init_it()”>
<a id=”FCS2″ href=”” onclick=”n(event)”>Focus other window</a>

</body></html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @starr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...