open a new window, then close the old one

N

Navillus

Hi all,

Trying to make a script function that opens a new window with a new
location, and then closes the old window. My function looks like this:

<script language="javascript">

function deletecook()
{
new_win = window.open('http://www.blahblahblah.com/')
window.close()
}
</script>

But it doesn't close any windows, not even the one it just opened. Any
takers?
 
N

Navillus

Navillus said:
Hi all,

Trying to make a script function that opens a new window with a new
location, and then closes the old window. My function looks like this:

<script language="javascript">

function deletecook()
{
new_win = window.open('http://www.blahblahblah.com/')
window.close()
}
</script>

But it doesn't close any windows, not even the one it just opened. Any
takers?

Sort of fixed it, because i was in a windowed page, so the fix was
top.window.close()
But it gives this buggy warning message asking if youre sure you want
to close the window... don't suppose there is a way to supress that?
 
A

ASM

Navillus a écrit :
Hi all,

Trying to make a script function that opens a new window with a new
location, and then closes the old window. My function looks like this:

<script language="javascript">

function deletecook()
{
new_win = window.open('http://www.blahblahblah.com/')
window.close()
}
</script>

But it doesn't close any windows, not even the one it just opened. Any
takers?

You can't close a window if it hasn't been opened by javascript
truc = window.open('page.htm');

in this context, 'page.htm' will be abble to close itself.

if it is
you could try :

function delecook() {
w = window.open('page.htm');
w.onload = self.close();
}
 
R

Randy Webb

Navillus said the following on 5/16/2006 9:18 PM:
Ever tested code such as that with the Symantec Popup Blocking Software?
Your code will not do what you think it should.
Sort of fixed it, because i was in a windowed page, so the fix was
top.window.close()
But it gives this buggy warning message asking if youre sure you want
to close the window... don't suppose there is a way to supress that?

Nope. You can't close a window you didn't open with script.

Don't close my windows, you don't have a problem.
 
B

Bart Van der Donck

Randy said:
[...]
Nope. You can't close a window you didn't open with script.
[...]

Yes you can, if the link was opened in a new window

1.htm:

<a href="2.htm" target="_blank">


2.htm:

<a href="#" onclick="self.close()">Close</a>
 
R

Randy Webb

Bart Van der Donck said the following on 5/17/2006 1:21 PM:
Randy said:
[...]
Nope. You can't close a window you didn't open with script.
[...]

Yes you can, if the link was opened in a new window

1.htm:

<a href="2.htm" target="_blank">


2.htm:

<a href="#" onclick="self.close()">Close</a>

Man o man, what a nice "feature" to have.
Doesn't work with a tab in Firefox but otherwise it does. Geez.
Opera lets you close it even in a new tab.
 
T

Thomas 'PointedEars' Lahn

Bart said:
Yes you can, if the link was opened in a new window

1.htm:

<a href="2.htm" target="_blank">


2.htm:

<a href="#" onclick="self.close()">Close</a>

Voodoo programming at its best.


PointedEars
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 5/22/2006 5:55 PM:
Voodoo programming at its best.

"Voodoo programming"? Where did you get that crap? It is a bug in every
single browser anybody tested it in. Exploiting that bug isn't "Voodoo
programming", calling it "Voodoo Programming" is, well, Voodoo at its best.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top