[thelist] Bringing windows to the foreground with javascript

Jeff jeff at members.evolt.org
Thu, 20 Jan 2000 14:08:24 -0800


bart,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Bart Johnston <00217289@bigred.unl.edu>
:
: I have a quick javascript question that's been buggin me for a while.  I'm
: building an online training site, and on this site there are terms that
the
: user can view definitions for in a popup window.  But I want to make sure
: that if they leave the definition window open in the background (hidden by
: the main browser window), that the definition widow will come back to the
: foreground if they click on another term.  I thought that I would be able
to
: use focus(), but I'm pretty sure I'm getting nowhere with it.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

your call to the variable "terms" is outside of the term() function which
means that the variable "terms" isn't defined globally and unavailable
outside the function.  you could get around this several ways, but i'll
explain the best solution for you.

first, you could define the variable outside your term() function like this:

var terms;
function term(word)
{
  var file2open = "../glossary/" + word + ".htm";
  terms=window.open(file2open,'terms','<options>');
}

however, your focus call in the onClick handler will throw errors in js1.0
browsers because the focus() method of the window object wasn't implemented
until js1.1.  that's why it's better to wrap the call to the window.focus()
method within a conditional that checks for support of the method, which is
best/most easily done within the actual function itself.  also, be careful
using the same name for the window as the variable that holds the window
reference.

function term(word)
{
  var file2open = "../glossary/" + word + ".htm";
  terms=window.open(file2open,'termsWin','<options>');
  if(terms.focus) { terms.focus(); }
}

there are other little things you could do to make this degrade well for
non-js browsers, holler if you wanna know.

good luck,

: jeff.howden
: web.development.professional
: evolt.org.member
:
: the.best.looking.developers.on.the.net
:
: http://evolt.org/
: jeff@members.evolt.org