最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable to get property of undefined or null reference - Stack Overflow

programmeradmin1浏览0评论

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'); 
} 

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'); 
} 
Share Improve this question edited Dec 29, 2012 at 17:11 mplungjan 178k28 gold badges181 silver badges240 bronze badges asked Dec 29, 2012 at 16:55 bnortonbnorton 432 gold badges2 silver badges4 bronze badges 5
  • did you open the child window using a script in the parent page? – mplungjan Commented Dec 29, 2012 at 17:01
  • Yes I did. It is opened as a modal window – bnorton Commented Dec 29, 2012 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 Commented Dec 29, 2012 at 17:04
  • Take a look at stackoverflow./questions/4885765/window-opener-alternatives it appears the showModalDialog is your problem – Dampsquid Commented Dec 29, 2012 at 17:08
  • Sorry for everything being inline. I tried to edit but I ran out of time. – bnorton Commented Dec 29, 2012 at 17:10
Add a ment  | 

1 Answer 1

Reset to default 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();
}
发布评论

评论列表(0)

  1. 暂无评论