Using dynamic variable as window name and detecting if window exists

L

lrlebron

I am trying to create popup windows with dynamic variable names and
then see if they exist or not.

For example, if I call the function like so openWin("2600","2000") I
would like the function to create a window called
"win26002000". I have tried the following code (and many other
variations) but I cannot get it to work

function openWin(senderID, recipientID)
{
//Create the window if it does not exist or it has been closed
if (typeof "win" + senderID + recipientID=="undefined" || "win" +
senderID + recipientID.closed)
{
"win" + senderID +
recipientID=window.open("popup.aspx","win" + senderID +
recipientID,"toolbar=no,menubar=no,width=350,height=350");
}
if("win" + senderID + recipientID)
{
//Do something with the window
}
}


thanks,

Luis
 
A

ASM

(e-mail address removed) a écrit :
I am trying to create popup windows with dynamic variable names and
then see if they exist or not.
For example, if I call the function like so openWin("2600","2000") I
would like the function to create a window called
"win26002000". I have tried the following code (and many other
variations) but I cannot get it to work


function openWin(senderID, recipientID) {
var W = window['win'+senderID+recipientID];
if( typeof(W)=='undefined' || W.closed)
W = window.open('','win'+senderID+recipientID,'width=350,height=350');
W.location = 'popup.aspx';
W.focus();
}

not tested ...
so perhaps :

function isWin(senderID, recipientID) {
return window['win'+senderID+recipientID];
}
function openWin(senderID, recipientID) {
if( typeof(isWin(senderID, recipientID))=='undefined' ||
isWin(senderID, recipientID).closed)
isWin(senderID, recipientID) = window.open('',
'win'+senderID+recipientID,
'width=350,height=350');
isWin(senderID, recipientID).location = 'popup.aspx';
isWin(senderID, recipientID).focus();
}
 
L

lrlebron

(e-mail address removed) a écrit :
I am trying to create popup windows with dynamic variable names and
then see if they exist or not.
For example, if I call the function like so openWin("2600","2000") I
would like the function to create a window called
"win26002000". I have tried the following code (and many other
variations) but I cannot get it to work

function openWin(senderID, recipientID) {
var W = window['win'+senderID+recipientID];
if( typeof(W)=='undefined' || W.closed)
W = window.open('','win'+senderID+recipientID,'width=350,height=350');
W.location = 'popup.aspx';
W.focus();

}

not tested ...
so perhaps :

function isWin(senderID, recipientID) {
return window['win'+senderID+recipientID];}

function openWin(senderID, recipientID) {
if( typeof(isWin(senderID, recipientID))=='undefined' ||
isWin(senderID, recipientID).closed)
isWin(senderID, recipientID) = window.open('',
'win'+senderID+recipientID,
'width=350,height=350');
isWin(senderID, recipientID).location = 'popup.aspx';
isWin(senderID, recipientID).focus();

}

I tried both functions you suggested but I'm geting the following
error:

Microsoft JScript runtime error: 'closed' is null or not an object

thanks,

Luis
 
A

ASM

(e-mail address removed) a écrit :
function openWin(senderID, recipientID) {
var W = window['win'+senderID+recipientID];
if( typeof(W)=='undefined' || W.closed)
W = window.open('','win'+senderID+recipientID,'width=350,height=350');
W.location = 'popup.aspx';
W.focus();

}

not tested ...

I tried both functions you suggested but I'm geting the following
error:

Microsoft JScript runtime error: 'closed' is null or not an object

I'm so sorry but I get no error (FF or IE Mac) with following example :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled</title>
<script type="text/javascript">
function openWin(senderID, recipientID) {
var W = window['win'+senderID+recipientID];
if( typeof(W)=='undefined' || W.closed)
W = window.open('','win'+senderID+recipientID,'width=250,height=100');
W.location = 'http://www.google.fr/intl/fr_fr/images/logo.gif';
W.focus();
}
</script>
</head>
<body>
<p><a href="javascript:eek:penWin('ytr','un')">test 1</a>
<p><a href="javascript:eek:penWin('ytr','de')">test 2</a>
<p><a href="javascript:eek:penWin('ytr','un')">test 1</a>
<p><a href="javascript:eek:penWin('gg','aa')">test 3</a>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top