3

This is similar to my last question but the problem is different. I use a separate javascript file for all of my javascript functions. That file is called by my main window, and is also called in a separate instance by my child windows. My code works with every browser except IE 9 and 10. I have not tested earlier versions of IE.

IE says the offending line is window.opener.savetoparent($targetval); My previous code was opener.savetoparent($targetval); and before that I simply made the changes to the parent from the child directly. I have also gone into IE and enabled protected mode as suggested in another article with no change in behavior. Savetoparent() is available to both the child and the parent so I must call it with opener for it to run in the parent.

The error I am getting is : Unable to get property 'savetoparent' of undefined or null reference. Here is the code:

function saveandclose($wintype, $propid) {

switch($wintype) {
    case 'ccdetail':
        var $targetval = $('#cc-total').val();
        var $fieldname = 'closingcoststotal';
        break;
}

window.opener.savetoparent($targetval);
closewindow();
}

The safe to parent function is:

function savetoparent($targetval) {
    $('#' + $parentloc).val($targetval);
    var $name = $('#' + $parentloc).attr("name");
    var $rawtargetval = jsstrtonum($targetval);
    processrvsave($propertyid, $name, $rawtargetval);   
    calcrvtotals();
}

Any light you can shed on this would be greatly appreciated.

window is launched like this

if(window.showModalDialog) { 
  window.showModalDialog($childname + '.php?ploc=' + $parentloc + '&propid=' + $propid, '', 'dialogWidth: ' + $winwidth + 'px; dialogHeight: ' + $winheight + 'px;') 
} 
else { 
  window.open($childname + '.php?ploc=' + $parentloc + '&propid=' + $propid, '', 'width=' + $winwidth + ', height=' + $winheight + ', modal=yes'); 
} 
mplungjan
  • 169,008
  • 28
  • 173
  • 236
bnorton
  • 43
  • 2
  • 2
  • 4
  • did you open the child window using a script in the parent page? – mplungjan Dec 29 '12 at 17:01
  • Yes I did. It is opened as a modal window – bnorton Dec 29 '12 at 17:02
  • The code to launch is if(window.showModalDialog) { window.showModalDialog($childname + '.php?ploc=' + $parentloc + '&propid=' + $propid, '', 'dialogWidth: ' + $winwidth + 'px; dialogHeight: ' + $winheight + 'px;') } else { window.open($childname + '.php?ploc=' + $parentloc + '&propid=' + $propid, '', 'width=' + $winwidth + ', height=' + $winheight + ', modal=yes'); } – bnorton Dec 29 '12 at 17:04
  • Take a look at http://stackoverflow.com/questions/4885765/window-opener-alternatives it appears the showModalDialog is your problem – Dampsquid Dec 29 '12 at 17:08
  • Sorry for everything being inline. I tried to edit but I ran out of time. – bnorton Dec 29 '12 at 17:10

1 Answers1

2

There is no opener in showModalDialog. Use the returnValue

Also there has not been a modal parameter on window.open in many years..

Here is how to use returnValue

if(window.showModalDialog) { 
  $targetval = window.showModalDialog($childname + '.php?ploc=' + $parentloc + '&propid=' + $propid, 
    window,
    'dialogWidth: ' + $winwidth + 'px; dialogHeight: ' + $winheight + 'px;'))
  if(targetval) savetoparent($targetval);
} 
else { 
  window.open($childname + '.php?ploc=' + $parentloc + '&propid=' + $propid, '', 'width=' + $winwidth + ', height=' + $winheight + ', modal=yes'); 
} 

then

function saveandclose($wintype, $propid) {
  var $targetval ="";
  switch($wintype) {
    case 'ccdetail':
      $targetval = $('#cc-total').val();
      // var $fieldname = 'closingcoststotal'; I do not see this used anywhere
      break;
  }

  if (window.opener) window.opener.savetoparent($targetval);
  else returnValue = $targetval;
  closewindow();
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236