Closing popup windows | | |
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) | | | | 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:
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. | | | | 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:
>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) | | | | 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/ | | | | 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) |  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|