Forum Moderators: open
I'be got a Help system that opens (via window.open) a new browser window. Now each page has it's own contextual help and when the user clicks on the help button a new window opens.
I would rather have the script check for the presence of the (previously) opened window to see if it has not been closed and open the page there, or else open a new window.
My script looks like this:
var helpWindow;function openHelp(page) {
var width = 900;
var height = 700;
var windowFeatures = "width=" + width + ",height=" + height + ",resizable,scrollbars";
if (!helpWindow ¦¦ helpWindow.closed) {
helpWindow=window.open(page,"Help",windowFeatures);
}
else {
helpWindow.location.href=page;
helpWindow.focus();
}
}
Shouldn't the window name ('Help') sort that out automatically.
ie. If a window is already open named, Help, then the new URL will open in that.
Come to think of it, it's the only way that can work across multiple pages.
..because you can't pass a reference to a window (or any object ref at all) across from one (sequencial) page to another. The only thing that can be passed (by any method) is a string.
If the name doesn't sort things out, then I do have another (sillier) idea.
if (windowName) windowName.href.location = '...help/page.html'; else helpWindow = open(...); I was under the impression that a global variable (being the window object) is created using the name of the window, but I've never had cause to test this.
If I'm talking nonsense - sorry.
Kaled.
The target attribute is the way to go here. It will automatically load into the previously opened window.
I've thought about the target but that does not help me to see if the window is open or not...
Why do you need to know if the window was open already? You could put a onunload script(in the popup) to determine if the window was opened previously.
function openHelp(page) {
var width = 900;
var height = 700;
var windowFeatures = "width=" + width + ",height=" + height + ",resizable,scrollbars";
window.open(page,"Help",windowFeatures);
} <a target="_new" href="popup.html" onclick="openHelp('popup.html'); return false;">go</a> The method above worked properly for me after I added a self.focus() on the popup.
Regards,
Birdman
[pre]
[blue]#---- page1.htm ---------------------------------------------------[/blue]<html>
<head><title>Page 1</title>
<link rel="stylesheet" href="aLittleStyle.css" type="text/css" />
<script src="popHelp.js" language="javascript"></script>
</head>
<body>
<h3 style="background-color:green;">Page 1</h3>
<button onclick="popHelp(1)">Help 1</button>
<a href="page2.htm" style="color:blue;">
link to page 2</a>
</body>
</html>
[blue]#---- page2.htm ---------------------------------------------------[/blue]
<html>
<head><title>Page 2</title>
<link rel="stylesheet" href="aLittleStyle.css" type="text/css" />
<script src="popHelp.js" language="javascript"></script>
</head>
<body >
<h3 style="background-color:blue;">Page 2</h3>
<button onclick="popHelp(2)">Help 2</button>
<a href="page1.htm" style="color:green;">
link to page 1</a>
</body>
</html>
[blue]#---- help1.htm ---------------------------------------------------[/blue]
<html>
<head><title>Help 1</title></head>
<body style="background-color:green;color:white;">
<h3>Help 1</h3>
</body>
</html>
[blue]#---- help2.htm ---------------------------------------------------[/blue]
<html>
<head><title>Help 2</title></head>
<body style="background-color:blue;color:white;">
<h3>Help 2</h3>
</body>
</html>
[blue]#---- popHelp.js --------------------------------------------------[/blue]
var helpWin;
function popHelp(id)
{
helpWin =
open('help'+id+'.htm', 'help','width=400,height=400');
helpWin.focus();
}
[blue]#---- aLittleStyle.css --------------------------------------------[/blue]
BODY {margin: 0 100px; font-family: verdana;}
H3 { color: white; padding:15px;}
BUTTON {display:block;margin-bottom:30px;}
A {font-size:16px;}
[blue]#------------------------------------------------------------------[/blue]
[/pre]
The problem was with the code being churned out by the Help creation programme (WebWorks). It is including some scripts that control the behaviour of the frames. One of these scripts is preventing new content from being written to an already open Help window (ie only internal links can determine the content), which means a new window is being opened!
Thanks again to everyone for their reply.