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.
JSV_focusWindow(winName)
n/a
The JSV_focusWindow function uses the following arguments.
Argument | Description |
winName |
The name of a window that may have been opened by
JSV_openWindow .
|
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
onLoad
function to JSV_onLoad
and use this in your window (see Example 1), or
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
n/a
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
Copyright © 1999-2000 Roaring Fork Software. All rights reserved.