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
|