Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #7900

Re: Second window

Message-ID <1542790.qVoOGUtdWV@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2011-11-01 14:50 +0100
Subject Re: Second window
Newsgroups comp.lang.javascript
References <4eafd7ad$0$6898$e4fe514c@news2.news.xs4all.nl>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Tom de Neef wrote:

> A user click will result in calling up and filling a secundary window.

_secondary_

> […]
>   var secondWindow = null;
> 
> function load2ndWindow(query) {
>   if (secondWindow) secondWindow.document.write(emptyDoc);
>   secondWindow =
> 
window.open(query,"Support","menubar,resizable,width=600,height=300,scrollbars");
>   secondWindow.focus();
> }
> {code}
> 
> This works as long as the main page is not reloaded. But when it is
> reloaded, the script is reloaded as well and the link between variable
> secondWindow and the secundary window is broken.
> I have two questions:
> a) how come that the browser will re-use the secundary window when
> load2ndWindow() is called after a page reload?

Same window name (here: Support).  RTFFAQ, RTFM, STFW.

> It seems more reasonable when it creates a new secundary window and leaves
> the existing one intact.

No, it does not.  The previous global execution context along with the 
global object and all its properties ceases to exist on reload of the 
document view.  So the DOM implementation has nothing to use as a reference 
but the window name.

> As it is though, this suits me.
> b) how can I clear this secundary window that is about to be re-used by
> the browser after the main page is reloaded and the secondWindow variable
> no longer points to it?

You will have to use the same window name so that window.open() returns a 
reference to the Window instance.

As it is, your approach is flawed.  document.write() will always overwrite 
the content if the document has been loaded, but it will not automatically 
close the output stream (you need document.close() for that).  window.open() 
will always replace what you might have written with document.write() 
before.

You should check if `secondWindow' refers to a Window (`secondWindow 
converts to true) that is not closed (`closed' property is false), and only 
call window.open() if neither is the case.  Feature-test the focus() method 
before you call it then, and catch any exceptions the call might still 
throw.

We have been over this ad nauseam, and recently.  Please search before you 
post.


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Second window "Tom de Neef" <tdeneef@qolor.nl> - 2011-11-01 12:27 +0100
  Re: Second window Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-01 14:50 +0100
    Re: Second window "Tom de Neef" <tdeneef@qolor.nl> - 2011-11-02 20:43 +0100
      Re: Second window "Tom de Neef" <tdeneef@qolor.nl> - 2011-11-02 20:51 +0100
      Re: Second window Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-02 21:25 +0100
        Re: Second window Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-02 21:35 +0100
          Re: Second window "Tom de Neef" <tdeneef@qolor.nl> - 2011-11-02 23:23 +0100

csiph-web