By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

FAQ Topic - How do I close a window and why does it not work on the first one?

P: n/a
-----------------------------------------------------------------------
FAQ Topic - How do I close a window and why does it not work on the first one?
-----------------------------------------------------------------------

Use `` windowRef.close() '', where windowRef is a window object
reference, such as window, top, parent, self, or a reference
obtained from the window.open() method. You can only close
windows opened by scripts, no others.

http://msdn.microsoft.com/workshop/a...ds/close_0.asp

http://docs.sun.com/source/816-6408-...ow.htm#1201822
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

Aug 26 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
FAQ server said the following on 8/26/2006 7:00 PM:
-----------------------------------------------------------------------
FAQ Topic - How do I close a window and why does it not work on the first one?
-----------------------------------------------------------------------

Use `` windowRef.close() '', where windowRef is a window object
reference, such as window, top, parent, self, or a reference
obtained from the window.open() method. You can only close
windows opened by scripts, no others.
That statement is about 20% true if it is that high a percentage.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 28 '06 #2

P: n/a
Randy Webb wrote:
FAQ server said the following on 8/26/2006 7:00 PM:
>-----------------------------------------------------------------------
FAQ Topic - How do I close a window and why does it not work on the
first one?
-----------------------------------------------------------------------

Use `` windowRef.close() '', where windowRef is a window object
reference, such as window, top, parent, self, or a reference
obtained from the window.open() method. You can only close
windows opened by scripts, no others.

That statement is about 20% true if it is that high a percentage.
Why is that? And why has the FAQ entry gone so long without change (on
this entry)?

(Note, I did not mean that to sound as if I were complaining it was
taking too long.)

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Apr 24 '07 #3

P: n/a
-Lost said the following on 4/23/2007 11:41 PM:
Randy Webb wrote:
>FAQ server said the following on 8/26/2006 7:00 PM:
>>-----------------------------------------------------------------------
FAQ Topic - How do I close a window and why does it not work on the
first one?
-----------------------------------------------------------------------

Use `` windowRef.close() '', where windowRef is a window object
reference, such as window, top, parent, self, or a reference
obtained from the window.open() method. You can only close
windows opened by scripts, no others.

That statement is about 20% true if it is that high a percentage.

Why is that?
Because at the time that I wrote that (8 months ago), I could close
about 80% of windows that weren't opened with JS and the user couldn't
stop me.
And why has the FAQ entry gone so long without change (on this entry)?
At the time I made my post, I had nothing to do with editing the FAQ and
I doubt very seriously you would have gotten Richard to change it. And
the chances of me including the security flaw to get around it are 0%.
And now, about half of them have been closed up in IE, FF and Opera so
there isn't a whole lot of point in putting it in the FAQ.
(Note, I did not mean that to sound as if I were complaining it was
taking too long.)
Wait another 5 years and the FAQ probably still won't be changed to
include any way to annoy users by closing windows.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 24 '07 #4

P: n/a
Randy Webb wrote:
-Lost said the following on 4/23/2007 11:41 PM:
>Randy Webb wrote:
>>FAQ server said the following on 8/26/2006 7:00 PM:
-----------------------------------------------------------------------
FAQ Topic - How do I close a window and why does it not work on the
first one?
-----------------------------------------------------------------------

Use `` windowRef.close() '', where windowRef is a window object
reference, such as window, top, parent, self, or a reference
obtained from the window.open() method. You can only close
windows opened by scripts, no others.

That statement is about 20% true if it is that high a percentage.

Why is that?

Because at the time that I wrote that (8 months ago), I could close
about 80% of windows that weren't opened with JS and the user couldn't
stop me.
>And why has the FAQ entry gone so long without change (on this entry)?

At the time I made my post, I had nothing to do with editing the FAQ and
I doubt very seriously you would have gotten Richard to change it. And
the chances of me including the security flaw to get around it are 0%.
And now, about half of them have been closed up in IE, FF and Opera so
there isn't a whole lot of point in putting it in the FAQ.
>(Note, I did not mean that to sound as if I were complaining it was
taking too long.)

Wait another 5 years and the FAQ probably still won't be changed to
include any way to annoy users by closing windows.
Sorry to hop on an old thread again, but I was wondering something.

You said that in times gone by you could close the majority of browsers.
I tested a wee bit of code and was wondering what drawbacks it had.
However, I do not wish to post it if it is a "security flaw."

I'd like to ask about it, how effective it is and whatnot, but again, I
am not posting something someone could use maliciously.

Can I possibly e-mail (a regular here) someone the code and get a
response? Or what should I do? Just post it?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 22 '07 #5

P: n/a
-Lost said the following on 5/21/2007 11:51 PM:
Randy Webb wrote:
>-Lost said the following on 4/23/2007 11:41 PM:
>>Randy Webb wrote:
<snip>
>>(Note, I did not mean that to sound as if I were complaining it was
taking too long.)

Wait another 5 years and the FAQ probably still won't be changed to
include any way to annoy users by closing windows.

Sorry to hop on an old thread again, but I was wondering something.

You said that in times gone by you could close the majority of browsers.
I tested a wee bit of code and was wondering what drawbacks it had.
However, I do not wish to post it if it is a "security flaw."
Any script that can close a window that script didn't open is exploiting
a security flaw :-)
I'd like to ask about it, how effective it is and whatnot, but again, I
am not posting something someone could use maliciously.

Can I possibly e-mail (a regular here) someone the code and get a
response? Or what should I do? Just post it?
Email it to the address in the FAQ for me. Put FAQ in the subject line
as that address gets about 30 spams a day and the FAQ will keep me from
getting trigger happy.

<URL: http://jibbering.com/faq/index.html#FAQ5_2>

The way a browser tells whether a script opened the window was by
checking the window.opener property. In IE6 (and prior) and some earlier
FF and Opera you could set the window.opener property yourself thereby
allowing you to close the window.

Another flaw that I have not tested in a while was that if a window was
opened via a link with a target attribute (target="someWindow") then the
child window could close itself with window.close() even though script
didn't open the window. You could even close it from the parent in IE
for a little while - someWindow.close() - even if it was opened via a
targeted link.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 22 '07 #6

P: n/a
Randy Webb wrote:
-Lost said the following on 5/21/2007 11:51 PM:
>Randy Webb wrote:
>>-Lost said the following on 4/23/2007 11:41 PM:
Randy Webb wrote:

<snip>
>>>(Note, I did not mean that to sound as if I were complaining it was
taking too long.)

Wait another 5 years and the FAQ probably still won't be changed to
include any way to annoy users by closing windows.

Sorry to hop on an old thread again, but I was wondering something.

You said that in times gone by you could close the majority of
browsers. I tested a wee bit of code and was wondering what drawbacks
it had. However, I do not wish to post it if it is a "security flaw."

Any script that can close a window that script didn't open is exploiting
a security flaw :-)
>I'd like to ask about it, how effective it is and whatnot, but again,
I am not posting something someone could use maliciously.

Can I possibly e-mail (a regular here) someone the code and get a
response? Or what should I do? Just post it?

Email it to the address in the FAQ for me. Put FAQ in the subject line
as that address gets about 30 spams a day and the FAQ will keep me from
getting trigger happy.

<URL: http://jibbering.com/faq/index.html#FAQ5_2>

The way a browser tells whether a script opened the window was by
checking the window.opener property. In IE6 (and prior) and some earlier
FF and Opera you could set the window.opener property yourself thereby
allowing you to close the window.

Another flaw that I have not tested in a while was that if a window was
opened via a link with a target attribute (target="someWindow") then the
child window could close itself with window.close() even though script
didn't open the window. You could even close it from the parent in IE
for a little while - someWindow.close() - even if it was opened via a
targeted link.
E-mail sent.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 22 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.