Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Can I clear the content of a window, or close it if it's not open.

Reply
Thread Tools

Can I clear the content of a window, or close it if it's not open.

 
 
Guy
Guest
Posts: n/a
 
      12-13-2003
I have 4 images on a page and when someone clicks on one of them I open a
secondary window and write a few lines to it describing the image.

If they don't close that secondary window however, and click on another of
these 4 images, my write commands print further down on that secondary
window.

I was reading through an old javascript book that talks about the
win1.document.clear(); method, but information on the Internet tells me that
this is now obsolete, or was just working on Netscape.

So then I decided to close the secondary window before re-opening it. But if
the user _did_ close the secondary window, I get an error saying that the
window I'm trying to close is already closed (or doesn't exist to be exact)!

Is there a way to clear the document in a window that I opened and wrote to?
Or is there a way to detect if win1 exists or not? If it exists, I would
close it. If it didn't exist, I would just re-open a new one.

Thanks for all.
Guy



 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-14-2003
Guy wrote:

> I have 4 images on a page and when someone clicks on one of them I open a
> secondary window and write a few lines to it describing the image.


What about popup blockers? What about people without a
UA who has client-side JavaScript support (enabled)?

> If they don't close that secondary window however, and click on another of
> these 4 images, my write commands print further down on that secondary
> window.


If you need only a popup, use target="foobar" for the a element.

If you need a special popup, search Google Groups for window.open.
This one is quite a FAQ. Once you have named a window it is reused
if already open and the same name is used.

> So then I decided to close the secondary window before re-opening it.


Bad idea because it eats system resources in flawed implementations
without (completely) freeing them afterwards.

> But if the user _did_ close the secondary window, I get an error saying that the
> window I'm trying to close is already closed (or doesn't exist to be exact)!


Ask Google about the `closed' property.

> Is there a way to clear the document in a window that I opened and wrote to?


Depends on how its content is composed. Generally, a
document.write(...) after load will overwrite the document
but as you do not want to exclude users without JavaScript,
you will not need that.

> Or is there a way to detect if win1 exists or not?


There is, search before you post.

> If it exists, I would close it.


Use the close() method then.

> If it didn't exist, I would just re-open a new one.


This is not always necessary nor recommended.


PointedEars
 
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
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 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
file.close() does not really close under Windows? Dani Python 3 12-17-2009 02:49 PM
this.Connection.Close(); does not close the Oracle session! Pleasehelp! S_K ASP .Net 6 12-07-2007 02:07 PM
document.close() on dynamic iframe on firefox does not close the connection. hyejin Javascript 8 08-29-2006 02:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57