2012-12-29 71 views
2

這與我最後一個問題類似,但問題不同。我爲所有的javascript函數使用單獨的JavaScript文件。該文件由我的主窗口調用,並且也在我的子窗口的單獨實例中調用。我的代碼適用於除IE 9和10以外的所有瀏覽器。我沒有測試早期版本的IE。無法獲取未定義或空引用的屬性

IE說有罪行是window.opener.savetoparent($targetval);我以前的代碼是opener.savetoparent($targetval);,在此之前我直接對孩子進行了修改。我也進入了IE並啓用了保護模式,正如另一篇文章中提到的那樣,行爲沒有變化。 Savetoparent()對孩子和父母都是可用的,所以我必須用opener調用它才能在父母中運行。

我得到的錯誤是:Unable to get property 'savetoparent' of undefined or null reference.這裏是代碼:

function saveandclose($wintype, $propid) { 

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

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

的安全父功能是:

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

您可以在此有何啓示,將不勝感激。

窗口推出這樣

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

沒有你使用父頁面中的腳本打開子窗口? – mplungjan

+0

是的,我做到了。它被打開一個模式窗口 – bnorton

+0

代碼推出是\t 如果(window.showModalDialog){ \t \t window.showModalDialog($ childname +名 '.php?PLOC =' + $ parentloc + '&PROPID =' + $ PROPID, '', 'dialogWidth:' + $ winwidth + 'PX; dialogHeight:' + $ winheight + 'PX;') \t}否則{ \t \t window.open($ childname + '.PHP PLOC ='? + $ parentloc +'&propid ='+ $ propid,'','width ='+ $ winwidth +',height ='+ $ winheight +',modal = yes'); \t} – bnorton

回答

2

中有沒有在showModalDialog開門紅。使用的returnValue

而且還沒有在多年來一直模態參數上window.open ..

這裏是如何使用的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'); 
} 

然後

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

謝謝。這工作。 – bnorton

相關問題