Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Second window for help

Reply
Thread Tools

Second window for help

 
 
Tom de Neef
Guest
Posts: n/a
 
      05-27-2011
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


 
Reply With Quote
 
 
 
 
Jeff North
Guest
Posts: n/a
 
      05-27-2011
On Fri, 27 May 2011 10:30:26 +0200, in comp.lang.javascript "Tom de
Neef" <(E-Mail Removed)>
<4ddf6124$0$49174$(E-Mail Removed)4all.nl> wrote:

>| 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;
}
--
-------------------------------------------------
The supplied code is for guideline purposes only.
 
Reply With Quote
 
 
 
 
Tom de Neef
Guest
Posts: n/a
 
      05-27-2011
"Jeff North" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> On Fri, 27 May 2011 10:30:26 +0200, in comp.lang.javascript "Tom de
> Neef" <(E-Mail Removed)>
> <4ddf6124$0$49174$(E-Mail Removed)4all.nl> wrote:
>
>>| 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;
> }


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


 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      05-27-2011
On May 27, 11:42 am, Tom de Neef wrote:
<snip>
> 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.
 
Reply With Quote
 
Tom de Neef
Guest
Posts: n/a
 
      05-27-2011
"Richard Cornford" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> On May 27, 11:42 am, Tom de Neef wrote:
> <snip>
>> 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).
>


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strip all but second second line from bottom and then strip that!!!! yelipolok Perl Misc 4 01-27-2010 08:14 AM
How can the change of second window trigger change of first window xhe Javascript 1 02-09-2007 06:16 PM
Active IE window open second IE window first collapses???? akaJOT Computer Support 1 08-04-2006 12:54 PM
refreshing main opener window from a second (popup) window sentinel Javascript 1 02-16-2004 01:56 PM
How to modify text on first window from child of second window? Juan Garcia Javascript 2 07-31-2003 05:11 PM



Advertisments