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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing window of window.open

Status
Not open for further replies.

jmcpher

Programmer
Jun 4, 2001
84
US
I am popping up a new window with window.open, and I am giving it a name, but I am not (and cannot for the cicumstances) storing the reference returned by window.open. How can I get a reference to this window later on in my script? (I can already cause other pages to load in it using window.open and passing the same name, but what I want to do is focus on it if it is open, and open it if it is not) "A computer scientist is a person who knows when it is time to hit the computer."

John

johnmc@mvmills.com
 
If I am understanding you correctly, the following code should help...(This is in VBSCript)

Set NewWindow = window.open(URL,WindowName,Featrues)

Then later in the code you can reference this window by just stating its name (NewWindow)

ex. NewWindow.focus Tazzmann
 
Nope, that is exactly what I can't do, I need to be able to access the window through something like document.all(myWindow) but this of course doesn't work. "A computer scientist is a person who knows when it is time to hit the computer."

John

johnmc@mvmills.com
 
ok, maybe I misunderstood what you are trying to explain.

You can't do it as it is giving you an error, not referencing the window properly, or just can't do it per some programming restrictions placed upon you? Tazzmann
 
Alright, heres the beef(how outdated is that saying?):

The user has two buttons on one window, both of which pop up there own window. Each one of the two sub-windows can also open the other sub-window. I don't want extra sub-windows popping up if the user trys to open a sub-window that is already open, I just want the window that the user tried to open to gain focus. Because any one of these windows can open a sub-window, the reference returned by window.open is not available to the window that has not opened another window.

I've just thought of a way to do it by having the functions for opening the sub-windows on the main window and just calling those functions from the sub-windows, but I am still hoping there is a cleaner way. "A computer scientist is a person who knows when it is time to hit the computer."

John

johnmc@mvmills.com
 
If you lay them out like the following, I believe it will accomplish what you want.

First Window:

<HTML>
<HEAD>
<script language=vbscript>
function Win1_onclick()
Set wind1 = window.open(&quot; &quot;wind1&quot;, _
&quot;resizable=1,toolbar=0,location=0,titlebar=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=500,height=325&quot;)
end function

function Win2_onclick()
Set wind2 = window.open(&quot; &quot;wind2&quot;, _
&quot;resizable=1,toolbar=0,location=0,titlebar=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=500,height=325&quot;)
end function
</script>
</HEAD>
<BODY>
<form ID=Test>
<input type=button ID=Win1 Value=&quot;Win1&quot;>
<input type=button ID=Win2 Value=&quot;Win2&quot;>
</form>
<P>&nbsp;</P>

</BODY>
</HTML>

Window 2:
<HTML>
<HEAD>
<script Language=VBScript>
function Win2_onclick()
Set wind2 = window.open(&quot; &quot;wind2&quot;, _
&quot;resizable=1,toolbar=0,location=0,titlebar=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=500,height=325&quot;)
end function
</script>
</HEAD>
<BODY>
<form ID=Test>
<input type=button ID=Win2 Value=&quot;Win2&quot;>
</form>
<P>&nbsp;</P>

</BODY>
</HTML>

Window 3:
<HTML>
<HEAD>
<script Language=VBScript>
function Win1_onclick()
Set wind1 = window.open(&quot; &quot;wind1&quot;, _
&quot;resizable=1,toolbar=0,location=0,titlebar=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=500,height=325&quot;)
end function
</script>
</HEAD>
<BODY>
<form ID=Test>
<input type=button ID=Win1 Value=&quot;Win1&quot;>
</form>
<P>&nbsp;</P>

</BODY>
</HTML>


On the child windows, by giving the name of the windows in the window.open the same as their original window name, you will not get multiple child windows opening. It will just refresh the child window. I think this is what you are trying to accomplish.
Tazzmann
 
Actually I don't think that would do what I want, but what I said about saving the reference on the main page and then calling the function from the sub-page worked. Thanks for your help and Happy Codings-) &quot;A computer scientist is a person who knows when it is time to hit the computer.&quot;

John

johnmc@mvmills.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top