Jump to content

Open Window


The Little Guy

Recommended Posts

I am trying to get this function to work:

 

function msgUsr(userID){
if(eval("!user_"+userID)){
	eval("var user_"+userID+" = window.open('/MCIM/msgbuddy.php?userID='+userID,'','scrollbars=no,menubar=no,height=300,width=400,resizable=yes,toolbar=no,location=no,status=no');");
}
}

 

It is supposed to check to see if a window is already open. the window var is created dynamically, the problem I am having, is the if statement, if when it gets there it says it can not find user_2 or user_3 and so on so what is wrong with that?

 

If the window is not found, it should go into the if statement, if the window is found, it should ignore the new window open.

Link to comment
Share on other sites

Try to avoid eval (search for "eval is evil")

 

You can do the same with using a simple JS object

 

<script language="javascript">
var wins = {};

function open_win(user_ID){
	if (!wins[user_ID]){
		wins[user_ID] = window.open("http://www.google.com", "", "");
	}
}
</script>
<input type="button" onclick="open_win(2);" value="Open" />

Link to comment
Share on other sites

add this function to your main window

 

function removeWin(user_ID){
    delete wins[user_ID];
}

 

and on the opended window, add an onunload event

 

<body onunload="opener.removeWin(user_ID);"...

 

Just make sure to use the same user_ID

 

Not tested. Both pages has to be in the same domain

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.