I am trying to write a script that will allow a window to create multiple popup windows and keep a reference to each popup window by populating an array. Then at anytime I want to access one of the child windows I can by finding it in the array and using that window object.
To make sure I can do this I made this script below which opens a page with some open window links and close window links. I should be able to open both windows and close both windows using the appropriate window objects from the array.
I have two problems with this script:
-
IE5.x gives me an “Access is denied” error on any line that tries to access the name property of a window. Why? I should be able to access this right?
-
Netscape will process the openWindow function just fine but bombs using the closeWindowByName() function. It seems to bomb on “if(newWindowsArray[i].name==winName).” I think it has to do with the name property of the window object again.
Any Help or ideas? The HTML for the document including the script is listed below
BEGIN HTML
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title>Untitled</title>
<script>
<!–
//the new window object handle
var newWindowsArray = new Array();
function openWindow(winURL, winName, winFeatures)
{
newWindow = window.open(winURL, winName, winFeatures);
newWindowsArray[newWindowsArray.length] = newWindow;
}
function closeWindowByName(winName)
{
for(i=0; i<newWindowsArray.length; i++)
{
if(newWindowsArray[i].name==winName)
{
alert(“works”);
newWindowsArray[i].close();
break;
}
}
}
//–>
</script>
</head>
<body>
<a href=“javascript:openWindow(‘http://www.sap.com’, ‘window1’, ‘height=300,width=300’)”>open window1</a>
<a href=“javascript:openWindow(‘http://www.sap.com’, ‘window2’, ‘height=300,width=300’)”>open window2</a>
<br><br>
<a href=“javascript:closeWindowByName(‘window1’)”>close window1</a>
<a href=“javascript:closeWindowByName(‘window2’)”>close window2</a>
</body>
</html>
END HTML