Solved

Detect/address child window on parent reload - IE8 only

Posted on 2012-04-06
8
505 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 9

Expert Comment

by:experts1
Comment Utility
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
Comment Utility
I never left ;) just hit 10mio points a few weeks ago
0
 

Author Comment

by:sailing_12
Comment Utility
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
Comment Utility
Cookie approach seems to work for me. Thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
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.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now