Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Reference to Opening Window

Status
Not open for further replies.

tschuler

Programmer
Jan 15, 2006
9
CY
I have code where a dialog box window needs to send data back to an opening window (3 back in the chain). This is my code:

Code:
   function HandleOK()
   {
      //window.alert("Close this window.");
      var RF_Obj = self.opener.opener.opener.document.DataEntryForm.RF_ComboBox;
      var MF_Obj = self.opener.opener.opener.document.DataEntryForm.MF_ComboBox;

      if (RFValuesArray[1] > 0)
      {
         // There is a record count value in the
         //  array, so a change has been made to the
         //  RF_ComboBox list, so the ComboBox on 
         //  the Data Entry page needs to
         //  be updated as well.
         // window.alert("Make refresh to RF_ComboBox.")
   	 RefreshListBox(RF_Obj, RFValuesArray, 1);
      }

      if (MFValuesArray[1] > 0)
      {
         // There is a record count value in the array, 
         //  so a change has been made to the
         //  MF_ComboBox list, so the ComboBox on the
         //  Data Entry page needs to
         //  be updated as well.FarkFor_ComboBox.")
   	 RefreshListBox(MF_Obj, MFValuesArray, 1);
      }

      window.returnValue = "";
      closeme();
   }

The code works just fine in Firefox and Netscape. But it does not work in Internet Explorer. It does not like my initial assignments using the opener property to get an object reference to the original opening window in the chain. My JavaScript reference book says that the opener property of the window object is supposed to be compatible with Internet Explorer version 3 and higher, as well as Firefox.

In Internet Explorer, I get the following error message:

Code:
An error has occurred in the script on this page.

Line:   791
Char:   5
Error:  'document.opener.opener' is null or not an object
Code:   0
URL:    [URL unfurl="true"]http://localhost:8500/[/URL] Sup...

Do you want to continue running scripts on this page?

I am using Internet Explorer version 6.0.2900.2180 and version 7.0.5730.13 and have the same results in both versions.

Does anyone know what I am doing wrong and how I can fix my code so it will also work in Internet Explorer as well as Firefox?
 
- Is the code above the portion that contains line 791? If not, could you post it?

- Do you have any reference to "document.opener" anywhere in your code? If so, try changing it to "window.opener".

- Can you post a URL to the page?


Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 

Line 791 points to the line of code that begins:
var RF_Obj = self.opener....

There is no "document.opener" anywhere in the code. I am not sure why the error message states it that way, because the code is "self.opener.opener.opener.document". That is the way the examples in my JavaScript reference show how to use the opener property. It also works perfectly in Firefox and Netscape.

There is no URL that I can give to you to view. The web program is in development on my own PC and not accessible outside my private network (i.e., it is not on a server that accesses the internet).

The mechanics of this are:
There is a main page ("Data Entry") that is always open. There is a menu bar with a menu item that opens up a modal dialog box (MS Windows terminology). That dialog box has a set of buttons that when clicked open up another modal dialog box. The second dialog box has some buttons that again open another modal dialog box. On that final dialog box there are an 'OK' and a 'Cancel' button. The 'OK' button, when clicked calls the event handler in my original post (the "HandleOK()" function). The handle OK function needs a reference to the window object of the main page (i.e., Data Entry page) so that it can transfer some data to the main page. That is what the self.opener.opener.opener code does. The remainder of that assignment gets me the reference to the exact text input control on the Data Entry page.

So basically, that whole assignment to the "RF_Obj" variable is:
window_obj.document_obj.control_obj

 

I might add...
if I delete from the code the 2 variable assignments at the start of the function and the 2 if constructs from the 'Handle_OK{}' function. The code for the entire page works without errors in Internet Explorer. (Of course, then I lose being able to set a new value on the Data Entry page in the input control of interest.)
 
Assuming you still want to use popups (and not go for a lightbox-style approach), I'd suggest creating a cut-down test harness that illustrates just the opener problem and make that publicly accessible.

This would be handy for 2 reasons:

1) If your test harness works, you know the error is somewhere else in your code

2) It allows us to debug without having to write reams of code!

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
OK, I figured out the problem.

My dialog boxes are opened with the showModalDialog() method of the window object instead of the window.open() method. And, according to my JavaScript reference, the showModalDialog() method does not maintain a connection to the originating window via the opener property.

Which begs the question, if Firefox/Mozilla can code their browsers to use the opener property with the showModalDialog() method, why can't the W3C make it a standard, and why can't Internet Explorer support it?

Anyway, if anyone is interested, I cut down the code to include the bare essentials and I can post the code if you want to look at it. It includes 4 files (the main page and the 3 dialog boxes).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top