473,388 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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

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
1 1762
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Videtta | last post by:
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...
2
by: Jack Black | last post by:
Hi, all!! Trying to clear the contents of a frame (or iframe), and can't seem to find anything that works. Tried: * innerHTML * outerHTML * document.close(); (with a number of different frame...
0
by: Mel_la_Bel | last post by:
Hi All, I'd like to get the content of windows(?), maybe they are MsgBoxes, that pop up in MS Word, like the ReadabilityStatistics after the Grammar check. Can I get control to the window that...
16
by: Jon | last post by:
Hi there, In many of my sites I have code like: <SCRIPT language="JavaScript" type="text/javascript"> <!-- user = "USER"; isp = "DOMAINNAME.XXX"; document.write('<a href=\"mailto:' + user +...
3
by: JezB | last post by:
I want to clear some specific Session variables when the user closes a page. On my page I have a "return to ..." button which navigates back to the parent page from which it was invoked - under the...
4
by: Xero | last post by:
Hello. How do you clear the content of a *.txt file? Thanks. -- Xero http://www.chezjeff.net My personal web portal
1
by: bbulsara23 | last post by:
Hi, this has been asked so many times before but I cannot get an answer that works. So I'm asking again. I am using .Net 1.1 on a Windows XP Pro.
1
by: sudip2008 | last post by:
When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm This breaks this line from working properly window.opener.document.forms...... How can...
13
by: sureshl | last post by:
JavaScript Experts, I have the following HTML. How could I use JavaScript such that when a user clicks on the checkbox in each row the phone numbers and e-mail addresses are partially obfuscated...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.