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

G

Guy

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
 
T

Thomas 'PointedEars' Lahn

Guy said:
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
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top