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

window.open Script

Status
Not open for further replies.

Tezdread

Technical User
Oct 23, 2000
468
GB
Hello there!

I have used the window.open function and it work fine, but what I would like to happen is when I click on another link, it first closes the open window before opening the new one?

Here is part of the script I am using at the moment, and hope that I can just add a new line into it?

<!--
function my_win()
{
window.open('design.htm','mywindow','width=250,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}
function my_win2()
{
window.open('domain.htm','mywindow','width=250,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}
//-->

Then the links are:
<a href=&quot;javascript:my_win()&quot;>link</a>
<a href=&quot;javascript:my_win2()&quot;link2</a>

And the link in the open window is:
<a href='javascript: window.close();'>Close Window</a>

I was hoping that I could just add window.close() to the open window link but unfortunatly not.

Thanks in advance if any one can help :)
 
I think you are trying to be able to keep both windows open.
If that's the case, you just need to change the script so that each window is named something differently:

window.open(&quot;page.htm&quot;,&quot;mywindow&quot;,&quot;options&quot;)

the second time you use window.open change the second arg:

window.open(&quot;page.htm&quot;,&quot;mywindow2&quot;,&quot;options&quot;)

this way the browser knows you wish to open a new one. You may also consider returning values from your window.open method:

winobj=window.open(&quot;page.htm&quot;,&quot;mywindow2&quot;,&quot;options&quot;)

this allows you to communicate with that window directly. for example, you can call someFunc() in the window you opened above by saying:

winobj.someFunc()

hope this helped!

jared@aauser.com
 
oops...i misunderstood the question just change your scripts to look like this:

Global_Current_Win = null;
function my_win()
{
if(Global_Current_Win){Global_Current_Win.close()}
Global_Current_Win = window.open('design.htm','mywindow','width=250,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}
function my_win2()
{
if(Global_Current_Win){Global_Current_Win.close()}
Global_Current_Win = window.open('domain.htm','mywindow','width=250,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}
jared@aauser.com
 
Thank you jaredn :) That works great, I was testing out a couple of other things like onBlur=&quot;self.close()&quot; and onBlur=&quot;self.focus()&quot; in the body tag, they both would have done the trick on their own when it came to IE but not in netscape (dam NN) the self.focus keeps the new window on top (in IE) but doesn't work in NN, and the same with the self.close one....Thank you again for you help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top