我正在尝试从弹出窗口调用父页面上的函数。我一直收到错误Object doesn't support property or method 'GetValueFromChild'.
我相信错误出现在弹出窗口的这一行 -
window.top.opener.parent.Xrm.Page.GetValueFromChild(person);
。我尝试使用window.opener.GetValueFromChild(person);
但仍然遇到同样的错误。任何帮助深表感谢。这是代码 -
//parent
$(document).ready(function () {
// This needs to be called from Child window
function GetValueFromChild(person) {
alert(person.Id);
alert(person.Name);
alert(person.Market);
}
});
//parent - jqgrid
colModel: [
{
name: 'Person', index: 'PersonName', width: 70, editable: true, edittype: 'button',
editoptions: {
value: 'Select',
dataEvents: [{
type: 'click',
fn: function (elem) {
var left = (screen.width / 2) - (700 / 2);
var top = (screen.height / 2) - (550 / 2);
var popup = window.open("popup.htm", "popup", "resizable=1,copyhistory=0,menubar=0,width=700,height=550,left='+left+',top='+top");
popup.focus();
}
}]
}
},
//弹出窗口。这个页面有另一个jqgrid和一个OK按钮。
$('#btnOK').click(function() {
var person= {
Id: grid.jqGrid('getCell', grid.getGridParam('selrow'), 'Id'),
Name: grid.jqGrid('getCell', grid.getGridParam('selrow'), 'Name'),
Market: grid.jqGrid('getCell', grid.getGridParam('selrow'), 'Market')
};
window.top.opener.parent.Xrm.Page.GetValueFromChild(person); //Error is on this line.
window.close();
});
答案 0 :(得分:1)
您的GetValueFromChild
范围限定为ready
回调。如果它不需要访问其他范围的函数和变量,那么只需在顶层声明它。如果确实需要访问它们,则需要在回调中创建对它的全局引用。
在顶级声明:
// This needs to be called from Child window
function GetValueFromChild(person) {
alert(person.Id);
alert(person.Name);
alert(person.Market);
}
从范围导出:
$(document).ready(function () {
// This needs to be called from Child window
function GetValueFromChild(person) {
alert(person.Id);
alert(person.Name);
alert(person.Market);
}
window.GetValueFromChild = GetValueFromChild;
});