Used to navigate to a specific window, and give it focus if it is open. Giving focus to a window brings the window forward in most windowing systems.

Syntax

JSV_focusWindow(winName)

Returns

n/a

Parameters

The JSV_focusWindow function uses the following arguments.

Argument Description
winName The name of a window that may have been opened by JSV_openWindow.

Remarks

In the article 30 JavaScript Tips, Charity Kahn provides this tip: Say you've opened a window with the function below (using object detection to check for support of the focus() method):

function openWindow(url, name) {
    popupWin = window.open(url, name, "width=300,height=200");
    if (window.focus) popupWin.focus();
} 

In Navigator 3.0 and later and IE 3.0, the window regains focus each time you call this function passing the same window name. But in IE 4.0, the second time you call the function from the same link you get an error message.

One method to avoid this problem is to call the focus() method in the head of each document that will be loaded into the pop-up.

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
if (window.focus) self.focus();
</SCRIPT>

If you experience this problem with JSV_focusWindow, you may

  1. try the above tip from BUILDER.COM,
  2. create an alternative window onLoad function to JSV_onLoad and use this in your window (see Example 1), or
  3. use a JavaScript browser detection script (e.g., The Ultimate JavaScript Client Sniffer by Netscape Communications) when using JSV_focusWindow in your code (see Example 2).

<HTML>
<HEAD>
    <!-- Your title and meta tags go here -->

    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    function onWindowLoad() {
        if (window.focus) self.focus();
        JSV_onLoad();
    }
    </SCRIPT>
</HEAD>

<BODY BGCOLOR="#FFFFFF" onLoad="onWindowLoad();">

<!-- Your document goes here -->

</BODY>
</HTML>

Example 1 - Use of focus in a JavaScript onLoad function

<SCRIPT LANGUAGE="JavaScript"
        TYPE="text/javascript"
        SRC="NS_ClientSniffer.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
if (window.focus && !is_ie4) JSV_focusWindow("MyWindow");
</SCRIPT>

Example 2 - Use of the The Ultimate Client Sniffer with JSV_focusWindow

Dependencies

n/a

Example

The following lines of code

var myWindow = "Jack_in_the_Box";
function focusMyWindow() {
    JSV_focusWindow(myWindow);
}

function openMyWindow() {
    var dummy = JSV_openWindow(myWindow,
        'testpage.htm',
        'menubar=1,status=1,scrollbars=1,resizable=1,width=580,height=240,left=40,top=40,screenX=40,screenY=40');
    JSV_blurWindow(myWindow);
}

produce