Solved

Determining if a child window exists

Posted on 2004-10-11
5
516 Views
Last Modified: 2010-05-18
I have a window that might possibly generate a child popUp window.  If one or more postbacks after a popup window was generated certain things change on the parent window, I want to refresh the data on the popup window.   I have no way of knowing if the popup window was ever created or if it is still open.   Below is some sample code.

var popupWindow;

function OpenPopup()  {                                          
    popupWindow = window.open("Popup.aspx", "pop", opts);
    popupWindow.focus();
}      


A reference to the new Window is assigned to the popupWindow variable during the rendering of the page, but after one or more postbacks, the popupWindow variable is null and no longer points to the existing popup window.   I can get the reference back by running the following code.

popupWindow = window.open("", "pop");
popupWindow .document.Form1.submit()

This works great if the popup window exists.  But if it does not then it just generates a new blank window which is bad.  My goal is to refresh the popup window if it exists but to do nothing if it does not exist already.   Is it possible to know if a window named "pop" exists without actually opening a new window if it does not exist?

0
Comment
Question by:wibleb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
devic earned 100 total points
ID: 12281821
hi wibleb,

welcome to my lab:
=====================
http://home.arcor.de/athens/expexc/js/window/check_if_window_exists/
0
 

Author Comment

by:wibleb
ID: 12282136
devic

This does not help me with my problem.  If you read my question carefully you will see that I need to know if a window exists when there is a postback between the time the window opened and the time I need to make the check.  On your pages, open up some popup windows, and then hit refresh on the parent page.  When you perform the check, it will always say the popup windows are closed even though they are not.  You can re-establish the reference by running code like

popupWindow = window.open("", "popupWindowName");

but it will open a blank window if the popup is not open.  


But don't fret, in what I consider a major flaw in this sites design, I am pretty sure I will end up giving the points to you anyways.  I am nearly certain that the answer is that it is not possible to do what I am trying to do, but I am forced to give the points to somebody.  
0
 
LVL 15

Assisted Solution

by:mr_egyptian
mr_egyptian earned 100 total points
ID: 12282599
wibleb-
Unless I don't follow you at all, I think this is what youre looking for. I tested this in IE6 and Firefox 0.9.1, as well as NN 4.7
This should be fairly self explanatory, but let me know if not. (Or if I misunderstood the problem)


<html>
 <head>
  <title></title>
  <script language="javascript">

   var popupWindow;

   function OpenPopup()  {                                  
       popupWindow = window.open("pop.html", "pop");
       popupWindow.focus();
   }

   function CheckPopup(){
       if(window.popupWindow && !window.popupWindow.closed){
           alert("Present");
       }else{
           alert("Absent");
       }
   }
     
  </script>
 </head>
<body>
<form name="frm" id="frm">
 <input type="button" value="Popup" onclick="OpenPopup();">
  <br>
 <input type="button" value="Check" onclick="CheckPopup();">
<form>
</body>
</html>
0
 

Author Comment

by:wibleb
ID: 12282911
mr_eqyptian

I believe this has the same problem as devic's.  You are assigning the popup window reference to a page variable.   Whenever there is a postback (such as refreshing the page), it clears all variables.  Try using your code to open a window, hit refresh, and hit check window.  It will say the popup window is absent even though it is still open.
0
 
LVL 25

Expert Comment

by:devic
ID: 12283320
wibleb, you are right.

we spoke some days ago about similar thema, and a solution was with cookie:
http:Q_21152932.html#12221611

I belive this is what you need.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question