Second window for help

T

Tom de Neef

A Help button in my app will open a second window where (context sensitive)
help is provided.
var helpWindow = window.open(...);
In response to user actions, the server will send a new page. The helpWindow
remains open but I loose the reference to it since with the new page also
the javascript is reloaded and initialized.
Is there a way to detect that the previously opened helpWindow is still
available and re-establish a reference to it?
Tom
 
J

Jeff North

| A Help button in my app will open a second window where (context sensitive)
| help is provided.
| var helpWindow = window.open(...);
| In response to user actions, the server will send a new page. The helpWindow
| remains open but I loose the reference to it since with the new page also
| the javascript is reloaded and initialized.
| Is there a way to detect that the previously opened helpWindow is still
| available and re-establish a reference to it?
| Tom
|

Why is the page refreshing? To prevent this you can use one of the
methods below
(this will work even if javascript is disabled)
<a href="#" onclick="window.open('help.html?id=123'); return
false;">Help</a>

or
<a href="#" onclick="return HelpWindow(123);">Help</a>
Javascript
function HelpWindow( id ) {
window.open("Help.html?id="+id);
return false;
}
 
T

Tom de Neef

Jeff North said:
Why is the page refreshing? To prevent this you can use one of the
methods below
(this will work even if javascript is disabled)
<a href="#" onclick="window.open('help.html?id=123'); return
false;">Help</a>

or
<a href="#" onclick="return HelpWindow(123);">Help</a>
Javascript
function HelpWindow( id ) {
window.open("Help.html?id="+id);
return false;
}

Thank you. I must be more precise. Consider following code is part of a page
(submitted by server):
var helpWindow = null;
function htmlHelp() {
if (!helpWindow) {helpWindow = window.open("index.htm","", ...)
}

The page has a menu button which calls htmlHelp(). It will open the
helpWindow unless it is already open.
Now the user calls up another page. That will also contain above code. The
page is replaced but the helpWindow stays open.
When now pressing the menu button, a new helpWindow is opened since variable
helpWindow = null again.
I want to prevent that. The function should act like
function htmlHelp() {
if there is a second window open for help provision (maybe created in a
previous document.write), then use that, otherwise create one
}

Tom
 
R

Richard Cornford

On May 27, 11:42 am, Tom de Neef wrote:
var helpWindow = null;
function htmlHelp() {
if (!helpWindow) {helpWindow = window.open("index.htm","", ...) ^^
}

The page has a menu button which calls htmlHelp(). It will open the
helpWindow unless it is already open.
Now the user calls up another page. That will also contain above
code. The page is replaced but the helpWindow stays open.
When now pressing the menu button, a new helpWindow is opened since
variable helpWindow = null again.
I want to prevent that. The function should act like
function htmlHelp() {
if there is a second window open for help provision (maybe created
in a previous document.write), then use that, otherwise create one

}

In principle, if a new window is given a name (the second argument to
the - window.open - call) then any subsequent call to - window.open -
using the _same_name_ while that window is open will load new content
into that already existing window (but possibly not bother if the new
content is the same as the old content), and only if the window has
been closed then a new window is opened. This sounds like what you are
asking for, and is also about as close as you are going to get to
being able to re-acquire a reference to an already open window.

Be cautious of the name that you use for the window. There are a set
of pre-defined names that you will want to be avoiding in this case,
and browsers vary in their tolerance of 'odd' names. Generally, a
single word (no spaces, and no digits only names) will work best, and
it is a good idea for it to be meaningful and (in so far as you can
arrange it) unique to your application (so you don't end up hijacking
other people's windows).

Richard.
 
T

Tom de Neef

Richard Cornford said:
On May 27, 11:42 am, Tom de Neef wrote:


In principle, if a new window is given a name (the second argument to
the - window.open - call) then any subsequent call to - window.open -
using the _same_name_ while that window is open will load new content
into that already existing window (but possibly not bother if the new
content is the same as the old content), and only if the window has
been closed then a new window is opened. This sounds like what you are
asking for, and is also about as close as you are going to get to
being able to re-acquire a reference to an already open window.

Be cautious of the name that you use for the window. There are a set
of pre-defined names that you will want to be avoiding in this case,
and browsers vary in their tolerance of 'odd' names. Generally, a
single word (no spaces, and no digits only names) will work best, and
it is a good idea for it to be meaningful and (in so far as you can
arrange it) unique to your application (so you don't end up hijacking
other people's windows).

So simple! Thank you very much. It works as needed.
Tom
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top