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

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

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.