Windows and Javascript - Clear contents.


R

Rob Videtta

Hi,

Please Help!

I have developed a custom JSP tag that produces Javascript to create a
window and write HTML and Javascript to that window. This window
displays an error message.

The problem is this. When the page with the custom tag is refreshed
without closing the (error) window the content written to the window
in the first place is written again. Thus, the error message appears
twice. The window source will then basically contain a replica of the
code, appended to the end of the first section of code. What I want
to do is clear the contents of the window before writing the HTML and
Javascript to that window. I have found a method document.clear()
which does not seem to be supported by IE. Does anyone know how I
achieve the same functinality?! Alternatively, I want to be able to
close the window and create a new window (with an error message) but I
don't know how I can check if the window is open. Remember that all
the functionality must be contained within the Javascript output by
the tag (the HTML page where the tag resides cannot be modified).

Any help would be much appreciated. Thanks,

Rob.
 
Ad

Advertisements

L

Lasse Reichstein Nielsen

The problem is this. When the page with the custom tag is refreshed
without closing the (error) window the content written to the window
in the first place is written again. Thus, the error message appears
twice.

Remember to close the document after writing to it (and open it before).
I.e., the code to write to the error window is

errorWindowRef.document.open();
errorWindowRef.document.write(errorContent);
errorWindowRef.document.close();
The window source will then basically contain a replica of the
code, appended to the end of the first section of code. What I want
to do is clear the contents of the window before writing the HTML and
Javascript to that window. I have found a method document.clear()
which does not seem to be supported by IE. Does anyone know how I
achieve the same functinality?!

Closing and reopening the document should be sufficient.
Alternatively, I want to be able to close the window and create a
new window (with an error message) but I don't know how I can check
if the window is open.

!(errorWindowRef.closed)

/L
 
Ad

Advertisements

L

Laurent Bugnion, GalaSoft

Hi,
Remember to close the document after writing to it (and open it before).
I.e., the code to write to the error window is

errorWindowRef.document.open();
errorWindowRef.document.write(errorContent);
errorWindowRef.document.close();

Just to be clear, document.write also opens the document if it was not
already open. As such, the call to document.open() before
document.write() is not necessary.

<snip>

Laurent
 

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

Top