Connecting Tech Pros Worldwide Forums | Help | Site Map

Closing popup windows

Ed Jay
Guest
 
Posts: n/a
#1: Jul 25 '06
I'm using the following simple js to open a popup window.

var popwin;
function launchwin(winurl,winname,winfeatures) {
popwin = window.open(winurl,winname,winfeatures);
}

Using the following to trigger the function:

<A
href="javascript:launchwin('help_1.html','newwindo w','height=300,width=300')">Help1</A>

There are up to ten different popups that can be launched from the same
page for context help, help1 - help10.

To close the windows, I include a link for self.close();

The problem I run into is that a user may not close a popup before
launching another, and the second popup doesn't grab focus.

I reason that if I launch a new window, but it closes other popups before
launching (or anything similar), I will solve the problem. The new problem
is that I haven't a clue how to do it.

Thoughts or direction? TIA,
--
Ed Jay (remove 'M' to respond by email)

Christopher Benson-Manica
Guest
 
Posts: n/a
#2: Jul 25 '06

re: Closing popup windows


Ed Jay <edMbj@aes-intl.comwrote:

(It's been a few months since I wrote any JS, so take this with a
grain of salt, or more.)
Quote:
var popwin;
function launchwin(winurl,winname,winfeatures) {
popwin = window.open(winurl,winname,winfeatures);
if( popwin ) {
popwin.focus();
}
Quote:
}
Quote:
The problem I run into is that a user may not close a popup before
launching another, and the second popup doesn't grab focus.
It can if you want it to.
Quote:
I reason that if I launch a new window, but it closes other popups before
launching (or anything similar), I will solve the problem. The new problem
is that I haven't a clue how to do it.
Store popped-up windows in a list or array somewhere, and iterate
through it and close all windows in it before popping up a new window.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Ed Jay
Guest
 
Posts: n/a
#3: Jul 27 '06

re: Closing popup windows


Christopher Benson-Manica scribed:
Quote:
>Ed Jay <edMbj@aes-intl.comwrote:
>
>(It's been a few months since I wrote any JS, so take this with a
grain of salt, or more.)
>
Quote:
>var popwin;
>function launchwin(winurl,winname,winfeatures) {
> popwin = window.open(winurl,winname,winfeatures);
if( popwin ) {
popwin.focus();
}
Quote:
>}
>
Quote:
>The problem I run into is that a user may not close a popup before
>launching another, and the second popup doesn't grab focus.
>
>It can if you want it to.
>
Quote:
>I reason that if I launch a new window, but it closes other popups before
>launching (or anything similar), I will solve the problem. The new problem
>is that I haven't a clue how to do it.
>
>Store popped-up windows in a list or array somewhere, and iterate
>through it and close all windows in it before popping up a new window.
Thanks, Christopher.

Here's where I ended up...at least to now:

URL: http://www.edbj.itnava.com/brca.html

var popwin;
function launchwin(winurl,winname,winfeatures) {
if (popwin) {popwin.close();}
popwin = window.open(winurl,winname,winfeatures);
popwin.focus();
}

This works...to an extent. If a window is manually closed, then an attempt
is made to open another window, the script fails with the error: 'Type
mismatch (usually a non-object value used where an object is required) --
if (popwin).'

I'm green at javascript, but it seems to me that the error arises because
popwin becomes an object and can't be tested for true/false. That said, I
tried testing it against 'null,' but got the same error.

Thoughts? Anyone?
--
Ed Jay (remove 'M' to respond by email)
Randy Webb
Guest
 
Posts: n/a
#4: Jul 27 '06

re: Closing popup windows


Ed Jay said the following on 7/27/2006 3:48 AM:
Quote:
Christopher Benson-Manica scribed:
>
Quote:
>Ed Jay <edMbj@aes-intl.comwrote:
>>
>(It's been a few months since I wrote any JS, so take this with a
>grain of salt, or more.)
>>
Quote:
>>var popwin;
>>function launchwin(winurl,winname,winfeatures) {
>> popwin = window.open(winurl,winname,winfeatures);
> if( popwin ) {
> popwin.focus();
> }
Quote:
>>}
>>The problem I run into is that a user may not close a popup before
>>launching another, and the second popup doesn't grab focus.
>It can if you want it to.
>>
Quote:
>>I reason that if I launch a new window, but it closes other popups before
>>launching (or anything similar), I will solve the problem. The new problem
>>is that I haven't a clue how to do it.
>Store popped-up windows in a list or array somewhere, and iterate
>through it and close all windows in it before popping up a new window.
>
Thanks, Christopher.
>
Here's where I ended up...at least to now:
>
URL: http://www.edbj.itnava.com/brca.html
>
var popwin;
function launchwin(winurl,winname,winfeatures) {
if (popwin) {popwin.close();}
popwin = window.open(winurl,winname,winfeatures);
popwin.focus();
}
>
This works...to an extent. If a window is manually closed, then an attempt
is made to open another window, the script fails with the error: 'Type
mismatch (usually a non-object value used where an object is required) --
if (popwin).'
>
I'm green at javascript, but it seems to me that the error arises because
popwin becomes an object and can't be tested for true/false.
Then test its type:

if ((typeof popwin) == 'object')

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Ed Jay
Guest
 
Posts: n/a
#5: Jul 27 '06

re: Closing popup windows


Randy Webb scribed:
Quote:
>Ed Jay said the following on 7/27/2006 3:48 AM:
Quote:
>Christopher Benson-Manica scribed:
>>
Quote:
>>Ed Jay <edMbj@aes-intl.comwrote:
>>>
>>(It's been a few months since I wrote any JS, so take this with a
>>grain of salt, or more.)
>>>
>>>var popwin;
>>>function launchwin(winurl,winname,winfeatures) {
>>> popwin = window.open(winurl,winname,winfeatures);
>> if( popwin ) {
>> popwin.focus();
>> }
>>>}
>>>The problem I run into is that a user may not close a popup before
>>>launching another, and the second popup doesn't grab focus.
>>It can if you want it to.
>>>
>>>I reason that if I launch a new window, but it closes other popups before
>>>launching (or anything similar), I will solve the problem. The new problem
>>>is that I haven't a clue how to do it.
>>Store popped-up windows in a list or array somewhere, and iterate
>>through it and close all windows in it before popping up a new window.
>>
>Thanks, Christopher.
>>
>Here's where I ended up...at least to now:
>>
>URL: http://www.edbj.itnava.com/brca.html
>>
>var popwin;
> function launchwin(winurl,winname,winfeatures) {
> if (popwin) {popwin.close();}
> popwin = window.open(winurl,winname,winfeatures);
> popwin.focus();
>}
>>
>This works...to an extent. If a window is manually closed, then an attempt
>is made to open another window, the script fails with the error: 'Type
>mismatch (usually a non-object value used where an object is required) --
>if (popwin).'
>>
>I'm green at javascript, but it seems to me that the error arises because
>popwin becomes an object and can't be tested for true/false.
>
>Then test its type:
>
>if ((typeof popwin) == 'object')
Thanks, Randy. This now works fine in IE and FF. Now if I can get it to
play in Opera, my development platform of choice, I'll be a very happy
camper. Thanks again.
--
Ed Jay (remove 'M' to respond by email)
Closed Thread


Similar JavaScript / Ajax / DHTML bytes