473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)
Jul 25 '06 #1
4 1904
Ed Jay <ed***@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.

--
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.
Jul 25 '06 #2
Christopher Benson-Manica scribed:
>Ed Jay <ed***@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. That said, I
tried testing it against 'null,' but got the same error.

Thoughts? Anyone?
--
Ed Jay (remove 'M' to respond by email)
Jul 27 '06 #3
Ed Jay said the following on 7/27/2006 3:48 AM:
Christopher Benson-Manica scribed:
>Ed Jay <ed***@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')

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 27 '06 #4
Randy Webb scribed:
>Ed Jay said the following on 7/27/2006 3:48 AM:
>Christopher Benson-Manica scribed:
>>Ed Jay <ed***@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)
Jul 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2438
by: MJEASSOC | last post by:
I need some help with closing a popup window. I'm making an online portfolio, that has one base page with text and thumbnails. When a user clicks on a thumb, a new window opens containing a larger...
7
3197
by: E Michael Brandt | last post by:
I have been lurking here for some time, and now would like to ask a question of you clever coders: My JustSo PictureWindow 3 Extension for Dreamweaver has stumbled in the face of the new Opera...
4
2049
by: bbass | last post by:
thanks to all that replyied to my previous post with the following code in question: <a href="merc.htm" target="_new_merc" onfocusout=window.close class="left_link"> i understand that the...
4
1337
by: Brian Mitchell | last post by:
Hello, I have an aspx app that executes the window.open to open a popup windows, but is there an easy way to close the popup? (I can't find a window.close method) Thanks!
3
1650
by: Chrysan | last post by:
I have a popup window, which consist of a asp:textbox and a asp:button. And, I would like to pass the textbox.text to the javascript function when I click the button. Besides, by clicking the...
4
2901
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
3
1927
by: =?Utf-8?B?Vk1J?= | last post by:
How can I close popup window automatically when I close the parent window (the application itself)? Thanks.
3
3867
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.