Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if popup exists

Status
Not open for further replies.

GaryC123

Programmer
Sep 10, 2002
1,041
NO
I'm just trying to find out if a popup window exists. I thought you could do this someway by referencing the name of the popup. Also there maybe more than one popup each with a different name. The creation of the popups is from some js code that keeps getting cycled.

By name I mean the myWindow part in for e.g. window.open("sompage.asp","myWindow",...)
All examples i see centre on the my myWin part in for e.g. var myWin=window.open .... which is how I currently open, but since there could be multiple windows open how can i reference individual windows which have different names assigned (the myWindow part is different for each window).
Also I need to be able to reference the popup if the user moves to another page in the parent window.

This is the code and the problem is occasionally if the main window finds a comment before the popup then it will open a new window

function state_Change(){
if (xmlhttp.readyState==4){
var to1
var name
if(xmlhttp.responseText!=""){
var p=xmlhttp.responseText
aData =p.split("|")
to1=aData[0]
name=aData[1]
if(to1!=0){
newwin = window.open('im_message.asp?to='+ to1 +'&name='+name,name+to1,'width=300,height=400')}
}}}


 
Not sure if I understand exactly, should it have the ... dots in there or filled in with the correct path.
The first just opens a new window.
The second clears the original window, which is no good. I need to keep whatever is in the popup there

 
the dots where simply to save space. you'd call that window.open function, but remember to store it in a variable (the [tt][blue]var myWin = [/blue][/tt]part of my code). then, you'd reference the variable name as I've shown you above.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
But that clears the original popup because its reopening the popup, I need to be able to check if it exists without doing that as the popup contains stuff that is constantly added to.

 
the code i gave you was a [tt]simple example[/tt] of how to check if a window is open. i'm sure you can take it and apply it to your code.

from the code you provided, i cannot tell where you'd want to perform your check, so i cannot tell you exactly where my solution would fit.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
I wouldnt be asking how to do this if I knew how. Your code clears the original popup which is as I've said no use. I need to be able to check if it exists without clearing it.

if(to1!=0){
// Must check here to see if the window is open
// Only proceed if it isn't
newwin = window.open('im_message.asp?to='+ to1 +'&name='+name,name+to1,'width=300,height=400')}
}}}

 

I don't think you can do that. Certainly not if you've changed pages, away from the opener, anyway.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
it is clearing the window because, as i said, the dots aren't supposed to be there. at the very top of your javascript, declare a variable.

Code:
var myWin;
now, you can check for the window's existence like this:
Code:
if (to1 != 0) {

    // if popup is closed, open it
    if ( !myWin || myWin.closed ) {
        myWin = window.open(...);
    }
}

does this help?

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
I usually make a simple object with a "closed" property and replace it with the window object once I create it (which also has a "closed" property).

Code:
var newwin={closed:true}
function state_Change(){
    if (xmlhttp.readyState==4){
        var to1, name;
        if(xmlhttp.responseText!=""){
            var p=xmlhttp.responseText;
            aData = p.split("|");
            to1 = aData[0];
            name = aData[1];
            if(to1! = 0){
                if(newwin.closed){
                    newwin=window.open('im_message.asp?to='+to1+'&name='+name,name+to1,'width=300,height=400')
                }
            }
        }
    }
}

Adam

There are only 10 types of people in the world: Those who understand binary, and those who don't
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top