[thelist] Bringing windows to the foreground with javascript

Aylard James J jaylard at equilon.com
Thu, 20 Jan 2000 15:51:47 -0600


Bart,

> <body onload="this.window.focus();return true;">

	One caution on the use of window.focus(): It will throw an error in
Nav2 and IE3. Jeff Howden and I bandied this about a few days ago, and the
two most-reliable solutions are to either test support for the focus method:

<script language="javascript" type="text/javascript">
  <!--
    if (window.focus) {
      self.focus() ;
    }
  // -->
</script>

Or to include the focus method between <script> tags with JavaScript 1.1
specified in the language attribute:

<script language="javascript 1.1" type="text/javascript">
  <!--
    self.focus() ;
  // -->
</script>

You can also plunk either of these snippets inside of a function and call it
from the <body> onLoad event handler, as you've done in your example. The
difference with doing it that way is that the window will not receive focus
until the page has finished loading.
	Jeff, catch me on anything that I've gotten wrong.

hth,
James Aylard
Equilon Enterprises LLC
jaylard@equilon.com