View Full Version : Detecting if pop-up is already open
slammer
07-24-2005, 01:42 AM
hey there. I have a small problem. I have a main window (hub.php) and from that there are links that pop up message boxes (its a messenger). Now, that works all fine. My php code goes to the database and checks if theres new messages, if there is i then need it to check if that contacts window is already open, if it is, do nothing, if it isnt then run the function i have for the pop up creation. The pop up windows are named by the contacts id, so i can easily match from the database to the window names etc.
Im not sure of the javascript code i should use to implement this checking of windows etc.
Hope someone can help.
Laters
Slammer
jscheuer1
07-24-2005, 10:05 AM
If I am following you correctly, and you are trying to avoid opening another window of the same name as an existing open window. As far as I know, you shouldn't worry about it. The browser will detect if that window is already open and instead of opening another, refresh the existing window's contents. Which again, if I am following you, would be a good thing. If this is not in line with what you are shooting for say, the new contents won't fit in the old window of the same name and you wish to replace it. Well, then assign a variable on window open:
var someWin=0 //declare this globally
if (someWin) //run these three lines locally as the occasion arises
someWin.close()
someWin=window.open(blah, blah, blah)K?
slammer
07-24-2005, 02:12 PM
hey, yes i know it will just refresh it if its already open, but i do not wish it to do this, as a refresh will clear the entire convo.
slammer
07-24-2005, 06:50 PM
i just did a test, and this is what my php output:
<script language='javascript'>
<!--
function convowindow()
{
convo2 = window.open('convo.php?cid=2',2,'width=500,height=400,menubar=no,scrollbars=no,toolbar=no,location=n o,directories=no,resizable=no,top=340,left=312');
if(id){
convo2.focus();
}else
{
convo2.open();
}
}
if (convo2)
{
}else{convowindow();}
//-->
</script>
now theres no window called convo2, but yet no window gets pop'd up. any iidea's?
slammer
07-25-2005, 01:37 PM
bump. Anyone?
jscheuer1
07-25-2005, 05:47 PM
What's a convo besides a name for the window? You have a link so we can see this happening?
yonni
07-25-2005, 08:33 PM
if i were you, i would get the popup to change a variable to "true" when it is opened, and change it back to "false" when it is closed. Thus, you can script it depending on wheather the variable is "true" or "false"
slammer
07-25-2005, 09:14 PM
What's a convo besides a name for the window? You have a link so we can see this happening?
This is part of a very large project, fully web-based messenger, own private network not using msn or yahoo protocols. So i wouldlnt be able to isolate this small section to show an example.
slammer
07-25-2005, 09:15 PM
if i were you, i would get the popup to change a variable to "true" when it is opened, and change it back to "false" when it is closed. Thus, you can script it depending on wheather the variable is "true" or "false"
hmmm, i have an idea about how to set it when its opened, but not sure how i would set it when its closed.
Is there not just a simple way to check if a window of a certain name is open? :S and use it in this way?
You need something like this
if (newWin && newWin.open && !newWin.closed)
which translates to;
if (newWin holds the window object and newWin.open exists, and newWin is not closed) then carry out the action
For more info see
www.huntingground.freeserve.co.uk/webplus/window/newwin2.htm
glenngv
07-26-2005, 06:56 AM
Try this:
function convowindow(cid){
var winVarName = "win"+cid;
if (!window[winVarName] || window[winVarName].closed){
window[winVarName] = window.open('convo.php?cid='+cid, 'convo'+cid, 'width=500, height=400, menubar=no, scrollbars=no, toolbar=no, location=no, directories=no, resizable=no, top=340, left=312');
}
window[winVarName].focus();
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.