Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detect/address child window on parent reload - IE8 only

Posted on 2012-04-06
8
Medium Priority
?
533 Views
Last Modified: 2012-06-27
I am opening a child window using the code below. From that window, I am reloading the parent document. When the parent document loads, I need to detect if there is the child window and, if so, extract a form element value to set a highlighted row in the reloaded parent document.

How do I reliably detect/address the spawned window on reload? This only needs to work for IE8 in a controlled environment.

*******************************************************************

window.onload = initPage;

function initPage() {

    document.form1.btnAddMedication.onclick = function () {
        var strURL = 'clientmedication_add.aspx?id=<%=clientid%>';
        var w = window.open(strURL, 'addMed', 'width=680,height=850,toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=yes');
    };

}
0
Comment
Question by:sailing_12
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 37817482
Why not either load the parent with the parameter or call a script in the parent to reload with the parameter or set a cookie before reload???
0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 37818404
A simple solution is to use a hidden master frame to retain the context and coordinate the creation of pop-up windows and reloading of subordinate frames.
0
 
LVL 9

Expert Comment

by:experts1
ID: 37820603
This solution should work for you!

It works with a setinterval loop in the child window
which sends a reminder every 5 seconds to parent window.
And the parent window checks every 5 seconds for the
signal from the child window:

JS code for parent window:
---------------------------
  var child_exist = false;

window.onload = function() {
  childCheck = setInterval ( "check_child()", 5000 );
}
  
function check_child() {
  if(child_exist) {
    alert("child window exists");
    clearInterval(childCheck);
   }
}

Open in new window

JS code for child window:
---------------------------
window.onload = function() {
  setInterval ( "alert_parent ( )", 5000 );
}

function alert_parent ( ) {
  if(window.opener) window.opener.child_exist = true;
}

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37820625
experts1

1) window.opener will likely disappear on reload

2) please code your future setIntervals and setTimeouts like this
setInterval(alert_parent, 5000 );
since using quotes is an impliit eval.


sailing_12

To get the handle of a window opened by name, open it again;

First time:

window.open("someUrlOntheSameServer","childWindow1");

second time

var childWindow = window.open("","childWindow1");
var someField = childWindow.document.forms[0].myField.value;

but I recommend cookies
0
 
LVL 9

Expert Comment

by:experts1
ID: 37820692
Hi  mplungjan!

Been like years I havent got a feedback from you.

Thanks for the reminder.

Cheers
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37820729
I never left ;) just hit 10mio points a few weeks ago
0
 

Author Comment

by:sailing_12
ID: 37823252
Thanks for all the feedback. I am currently working the cookie approach to see if it meets my needs.
0
 

Author Closing Comment

by:sailing_12
ID: 37883433
Cookie approach seems to work for me. Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

916 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