Second window for help

Discussion in 'Javascript' started by Tom de Neef, May 27, 2011.

  1. Tom de Neef

    Tom de Neef Guest

    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
    Tom de Neef, May 27, 2011
    #1
    1. Advertising

  2. Tom de Neef

    Jeff North Guest

    On Fri, 27 May 2011 10:30:26 +0200, in comp.lang.javascript "Tom de
    Neef" <>
    <4ddf6124$0$49174$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.
    Jeff North, May 27, 2011
    #2
    1. Advertising

  3. Tom de Neef

    Tom de Neef Guest

    "Jeff North" <> schreef in bericht
    news:...
    > On Fri, 27 May 2011 10:30:26 +0200, in comp.lang.javascript "Tom de
    > Neef" <>
    > <4ddf6124$0$49174$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
    Tom de Neef, May 27, 2011
    #3
  4. 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.
    Richard Cornford, May 27, 2011
    #4
  5. Tom de Neef

    Tom de Neef Guest

    "Richard Cornford" <> schreef in bericht
    news:...
    > 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
    Tom de Neef, May 27, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    2
    Views:
    3,071
  2. Juan Garcia
    Replies:
    2
    Views:
    109
    Juan Garcia
    Jul 31, 2003
  3. sentinel
    Replies:
    1
    Views:
    155
    kaeli
    Feb 16, 2004
  4. yelipolok
    Replies:
    4
    Views:
    240
    John W. Krahn
    Jan 27, 2010
  5. xhe
    Replies:
    1
    Views:
    117
    Randy Webb
    Feb 9, 2007
Loading...

Share This Page