You are here: irt.org | FAQ | JavaScript | Window | Q645 [ previous next ]
You can set a window as being the "active" window by giving it the focus:
windowName.focus()
You can wrap that up with the window creation using:
windowName = window.open('blah.htm'); windowName.focus();
This is only possible in JavaScript 1.1, so you might want to code two different functions, one which does this and one which doesn't:
<SCRIPT LANGUAGE="JavaScript"><!-- function openMyWindow() { windowName = window.open('blah.htm'); } //--></SCRIPT> <SCRIPT LANGUAGE="JavaScript1.1"><!-- function openMyWindow() { windowName = window.open('blah.htm'); windowName.focus(); } //--></SCRIPT>
The following was submitted by Dave Watts
As was said in a previous answer, you use <window>.focus( ) to bring the window to the front. Adding this time to a function to open the window can be a pain if you're using an inline window open (with onClick and the like).
You can achieve the same result by adding the following to the <head> of the window you are opening:
<script language="JavaScript"> <!-- self.focus(); //--> </script>
Then, when the page is loaded (or loaded again) it brings itself forward. I did this for my vanity site's remote webcam window. This is the link used to open the window (pretty much standard):
<a href="#" onClick="window.open('camremote.html','camWindow','menubar=no,status=no,scrollbars=no,resizable=no,width=320,height=240,toolbar=no,location=no,directories=no'); return false;">Remote Cam</a>
This is the page that is opened:
<html> <head> <title>Remote Cam</title> <script language="JavaScript"><!-- // Bring self to the front self.focus(); --></script> </head> <body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"> <applet code="visionGS.class" width="320" height="240"> <param name="refresh" value="30"> <param name="image" value="./cam/cam.jpg"> </applet> </body> </html>