Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #7897 > unrolled thread
| Started by | "Tom de Neef" <tdeneef@qolor.nl> |
|---|---|
| First post | 2011-11-01 12:27 +0100 |
| Last post | 2011-11-02 23:23 +0100 |
| Articles | 7 — 2 participants |
Back to article view | Back to comp.lang.javascript
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
| From | "Tom de Neef" <tdeneef@qolor.nl> |
|---|---|
| Date | 2011-11-01 12:27 +0100 |
| Subject | Second window |
| Message-ID | <4eafd7ad$0$6898$e4fe514c@news2.news.xs4all.nl> |
A user click will result in calling up and filling a secundary window. When
that secundary window already exists, it should be cleared so that the user
sees the window empty while waiting for a respons from the server. When the
secundary window does not yet exist, it should be created and focused and
then filled.
I have used this code:
{code}
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? It seems more reasonable when
it creates a new secundary window and leaves the existing one intact. 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?
I hope that I have described my problem adequately.
Thank you,
Tom
[toc] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-11-01 14:50 +0100 |
| Message-ID | <1542790.qVoOGUtdWV@PointedEars.de> |
| In reply to | #7897 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Tom de Neef" <tdeneef@qolor.nl> |
|---|---|
| Date | 2011-11-02 20:43 +0100 |
| Message-ID | <4eb19d6a$0$6851$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #7900 |
"Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote:
>
> 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.
>
Thank you. But...
function load2ndWindow(query) {
if (secondWindow && !secondWindow.closed) secondWindow.clear();
secondWindow = window.open(query,"Support", ...);
}
Loading the query results from the server may take some time. I want to
avoid the situation where the user sees obsolete previous data in the
support window.
There are three situations to consider:
a) a support window does not exist (never created or closed by user). The
function works fine. An empty support window will show up. Browser waits for
data and then shows it.
b) the support window exists and the secondWindow global variable is
associated with it. The function works fine. The support window gets the
focus (if needed that can be added to the code), is cleared and remains
virgin until new data arrives.
c) a support window exists but (due to reloading of the main page) the
global secondWindow has value null. What happens now is: the support window
gets the focus and shows obsolete data while waiting for the new data to
arrive from the server.
This last situation I want to avoid. Is there a way to associate the
variable secondWindow with an existing window, other than via window.open? I
now use:
//code//
function clear2ndWindow() {
if (secondWindow && !secondWindow.closed) {
secondWindow.document.body.innerHTML = ' ';
return true}
else return false
}
function load2ndWindow(query) {
// make sure second window is cleared
if (!clear2ndWindow()) secondWindow =
window.open('',"PRNinsightSupport","menubar,resizable,width=600,height=300,scrollbars");
secondWindow =
window.open(query,"PRNinsightSupport","menubar,resizable,width=600,height=300,scrollbars");
try {secondWindow.focus()} catch (e) {};
}
//code//
and this works for all three situations but it seems a bit daft to call
window.open('',...) prior to calling window.open(url,...).
(I will put a try..catch around the focus() call
Tom
[toc] | [prev] | [next] | [standalone]
| From | "Tom de Neef" <tdeneef@qolor.nl> |
|---|---|
| Date | 2011-11-02 20:51 +0100 |
| Message-ID | <4eb19f2c$0$6846$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #7936 |
"Tom de Neef" <tdeneef@qolor.nl> schreef in bericht
news:4eb19d6a$0$6851$e4fe514c@news2.news.xs4all.nl...
> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote:
>>
> There are three situations to consider:
> a) a support window does not exist (never created or closed by user). The
> function works fine. An empty support window will show up. Browser waits
> for data and then shows it.
> b) the support window exists and the secondWindow global variable is
> associated with it. The function works fine. The support window gets the
> focus (if needed that can be added to the code), is cleared and remains
> virgin until new data arrives.
> c) a support window exists but (due to reloading of the main page) the
> global secondWindow has value null. What happens now is: the support
> window gets the focus and shows obsolete data while waiting for the new
> data to arrive from the server.
>
> This last situation I want to avoid. Is there a way to associate the
> variable secondWindow with an existing window, other than via window.open?
> I now use:
> //code//
> function clear2ndWindow() {
> if (secondWindow && !secondWindow.closed) {
> secondWindow.document.body.innerHTML = ' ';
> return true}
> else return false
> }
>
> function load2ndWindow(query) {
> // make sure second window is cleared
> if (!clear2ndWindow()) secondWindow =
> window.open('',"PRNinsightSupport","menubar,resizable,width=600,height=300,scrollbars");
> secondWindow =
> window.open(query,"PRNinsightSupport","menubar,resizable,width=600,height=300,scrollbars");
> try {secondWindow.focus()} catch (e) {};
> }
> //code//
>
> and this works for all three situations but it seems a bit daft to call
*** Oeps, sorry it does not work in situation c ***
I had forgotten to remove a clear2ndWindow() which is called in
windows.onunload.
I give up
Tom
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-11-02 21:25 +0100 |
| Message-ID | <3007137.SPkdTlGXAF@PointedEars.de> |
| In reply to | #7936 |
Tom de Neef wrote:
> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote:
>> 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.
>
> Thank you. But...
>
> function load2ndWindow(query) {
> if (secondWindow && !secondWindow.closed) secondWindow.clear();
> secondWindow = window.open(query,"Support", ...);
> }
>
> Loading the query results from the server may take some time. I want to
> avoid the situation where the user sees obsolete previous data in the
> support window.
I did not think of that. Your approach is sound then if you close the
output stream. However, you might want to write a complete HTML document
then, as I am not sure that all browsers would automatically wrap the text
in one. And never have a textual empty document; this is not user-friendly.
But see below.
> There are three situations to consider:
> […]
> c) a support window exists but (due to reloading of the main page) the
> global secondWindow has value null. What happens now is: the support
> window gets the focus and shows obsolete data while waiting for the new
> data to arrive from the server.
>
> This last situation I want to avoid. Is there a way to associate the
> variable secondWindow with an existing window, other than via window.open?
No, but there is another possibility: You can focus an existing popup window
only when its content has been loaded, preferably in the `load' listener of
the new support document's body (`onload' attribute value).
HTH
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-11-02 21:35 +0100 |
| Message-ID | <1550319.qVoOGUtdWV@PointedEars.de> |
| In reply to | #7938 |
Thomas 'PointedEars' Lahn wrote: > […] You can focus an existing popup window only when its content has been > loaded, preferably in the `load' listener of the new support document's > body (`onload' attribute value). But this is not very user-friendly, too, for the user might wait a long time without seeing any reaction to their action. I can see no viable alternative to it, though. It would probably be best if you indicated to them that they need to wait some time. Possibilities that spring to mind is a "loading" message in the opener and a change of pointer cursor in the opener issued by popup code that is reverted by popup code when everything has been loaded. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
[toc] | [prev] | [next] | [standalone]
| From | "Tom de Neef" <tdeneef@qolor.nl> |
|---|---|
| Date | 2011-11-02 23:23 +0100 |
| Message-ID | <4eb1c2e1$0$6864$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #7939 |
"Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote: > >> [.] You can focus an existing popup window only when its content has been >> loaded, preferably in the `load' listener of the new support document's >> body (`onload' attribute value). > > But this is not very user-friendly, too, for the user might wait a long > time > without seeing any reaction to their action. Indeed. >I can see no viable alternative to it, though. > > It would probably be best if you indicated to them that they need to wait > some time. Possibilities that spring to mind is a "loading" message in > the > opener and a change of pointer cursor in the opener issued by popup code > that is reverted by popup code when everything has been loaded. I agree. Thank you. Tom
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web