Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > open a new window, then close the old one

Reply
Thread Tools

open a new window, then close the old one

 
 
Navillus
Guest
Posts: n/a
 
      05-17-2006
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?

 
Reply With Quote
 
 
 
 
Navillus
Guest
Posts: n/a
 
      05-17-2006

Navillus wrote:
> 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?

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      05-17-2006
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();
}

--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      05-17-2006
Navillus said the following on 5/16/2006 9:18 PM:
> Navillus wrote:
>> 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/')


Ever tested code such as that with the Symantec Popup Blocking Software?
Your code will not do what you think it should.

>> 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?
>


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

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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      05-17-2006
Randy Webb wrote:

> [...]
> 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>

--
Bart

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      05-17-2006
Bart Van der Donck said the following on 5/17/2006 1:21 PM:
> Randy Webb wrote:
>
>> [...]
>> 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.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      05-22-2006
Bart Van der Donck wrote:

> Randy Webb wrote:
>> 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>


Voodoo programming at its best.


PointedEars
--
This is Usenet. It is a discussion group, not a helpdesk. You post
something, we discuss it. If you have a question and that happens to get
answered in the course of the discussion, then great. If not, you can
have a full refund of your membership fees. -- Mark Parnell in alt.html
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      05-23-2006
Thomas 'PointedEars' Lahn said the following on 5/22/2006 5:55 PM:
> Bart Van der Donck wrote:
>
>> Randy Webb wrote:
>>> 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>

>
> 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to open a new window then close it but retain session? Alexey Smirnov ASP .Net 3 05-26-2010 02:16 PM
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
is better to open, write, close file than open, write, append, close? Iulian Ilea Javascript 1 12-21-2006 04:32 PM
how to open and then close a new window? john ASP General 2 01-30-2006 06:36 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM



Advertisments