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
https://forums.phpfreaks.com/topic/90024-open-window/
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
https://forums.phpfreaks.com/topic/90024-open-window/#findComment-461869
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
https://forums.phpfreaks.com/topic/90024-open-window/#findComment-462171
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.