473,657 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing to see if a window is open

Hello all,
I am trying to check if my new window is open and if it is change the url.
This works until I use the x in the corner to close the window. At that
point i get an error when i try to open the window again. I believe that it
is because newWindow is still active. How do I close newWindow when it is
unloaded or closed by the x. If this is truely the problem.

function openWindow()
{
if (typeof (newWindow) == "undefined" || newWindow.open == false)
{
newWindow = window.open("ht tp://www.yahoo.com", "","width=400,h eight=400");
newWindow.focus ();
return false;
}
else
{
newWindow.locat ion.href = "http://www.msn.com"
}
}

Here's my solution, seems a little redundant though.
function openWindow()
{
if (typeof (newWindow) == "undefined" || newWindow.open == false)
{
newWindow = window.open("ht tp://www.yahoo.com", "","width=400,h eight=400");
newWindow.focus ();
return false;
}
else
{
newWindow.close ()
newWindow = window.open("ht tp://www.msn.com/","","width=400 ,height=400");
newWindow.focus ();
return false;
}
}

Any help would be great, but it's not urgent as I have something that works.
Steve
Jul 23 '05 #1
1 1509

Steve Karnath (remove this text) wrote:
Hello all,
I am trying to check if my new window is open and if it is change the url. This works until I use the x in the corner to close the window. At that point i get an error when i try to open the window again. I believe that it is because newWindow is still active. How do I close newWindow when it is unloaded or closed by the x. If this is truely the problem.

function openWindow()
{
if (typeof (newWindow) == "undefined" || newWindow.open == false)
{
newWindow = window.open("ht tp://www.yahoo.com", "","width=400,h eight=400"); newWindow.focus ();
return false;
}
else
{
newWindow.locat ion.href = "http://www.msn.com"
}
}

Here's my solution, seems a little redundant though.
function openWindow()
{
if (typeof (newWindow) == "undefined" || newWindow.open == false)
{
newWindow = window.open("ht tp://www.yahoo.com", "","width=400,h eight=400"); newWindow.focus ();
return false;
}
else
{
newWindow.close ()
newWindow = window.open("ht tp://www.msn.com/","","width=400 ,height=400"); newWindow.focus ();
return false;
}
}

Any help would be great, but it's not urgent as I have something that works. Steve

----------------------------------------------------------------------

Hey, I have some sample code, it's so old, I'm not sure it works,
but why don't you try this:

if (oWindow2==null || oWindow2.closed )
.....
where oWindow2 is the object reference (not the name of the window),
and is saved as a global javascript variable (outside any function).
This ostensibly tests to see if the window is closed.
Bruce Brodinsky

Jul 23 '05 #2

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

Similar topics

1
1333
by: laxmi | last post by:
Is there a way to test whether a named window is open from a separate window which may not have opened the window? I have tried using: if(windowname == null) win = window.open(...) This gives an error that windowname is undefined if(window.windowname) doesn't work either (no error, but fails to
10
11219
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#" onClick="window.open('/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+PRODUCT%27<b>S+NAME+GOES', 'fullimage', 'WIDTH=420,HEIGHT=405,status=0')"> The original window should not reload, but is, and I have tested it with both version 4.72 and 7.02, and they both do it. IE does not do it....
3
24691
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The situation is: A main window opens child windows one at a time as the user requests, each with its own name. The user may click in any child window or the main window to open a summary window, which has a name all windows know. I want to get that...
6
5733
by: gsb | last post by:
Don't know if this is the right place to post this JavaScript issue. If not, could someone point me in the right direction please. I am trying to make a "cross browser compliant" floating iFrame. Not real fancy, just load, resize and move. But, I do not have the browsers, OSs and different machines (like Mac) to test the code on. So I need some help to see where this basic example of works and does not work.
14
11074
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
0
1177
by: calfdog | last post by:
I am pleased to announce version cPAMIE 1.6 the Web automation tool for Internet explorer. If your looking for a fast way, easy to learn way to drive your browser check out PAMIE. Is PAMIE right for you?, depends on your needs and complexity of the web application. Pamie can take care of the basic needs such as driving web forms without a problem.
7
3660
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses pageA.html 2. User clicks on menu link to open popup.html 3. pageA.html checks if popup.html is already open. It is not, open
3
1316
by: Ant | last post by:
Hi, Does anybody here know how to test user controls on the fly. I build the user control, as well as the application I am testing it in but the changes made to the user control aren't seen unless I close & reopen the project. There must be a simpler way... Any ideas, or at least point me to the right thread on which I can post this question would be a great help. Thanks in advance Ant
11
2352
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have realized that despite suggestions to use DHTML-based modal dialogs are very common? there is not a single fully functional reliable copyright-free cross-browser alternative to say MsgBox (VBScript) or showModalDialog (IE). This way such suggestions up to...
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 we have to send another system

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.