SharePoint 2013 showModalDialog 弹出模式窗口

时间:2023-03-08 17:34:28
SharePoint 2013 showModalDialog 弹出模式窗口

1. SharePoint 弹出框

本文讲述SharePoint 2013 中使用 SP.UI.ModalDialog.showModalDialog时 showModalDialog  未定义的问题。

function showDialog(title,url,width,height) {
var options = {
url:url,
args: 7,
title: title,
dialogReturnValueCallback: dialogCallback
};
if (width != undefined) options.width = width;
if (height != undefined) options.height = height; SP.UI.ModalDialog.showModalDialog(options); } //接收返回值方法
function dialogCallback(dialogResult, returnValue) {
//其中dialogResult=1,代表确定,dialogResult=0,代表关闭
if (returnValue != null && dialogResult == 1) { }
return;
}

上面的代码在SharePoint 2010中是可以正常工作的,就是显示一个 有模式的窗口。

但在SharePoint  2013 中会出现 (ModalDialog )showModalDialog  未定义的错误,如何解决这个问题呢?使用  SP.SOD.executeFunc :

 function showDialog(title,url,width,height) {
var options = {
url:url,
args: 7,
title: title,
dialogReturnValueCallback: dialogCallback
};
if (width != undefined) options.width = width;
if (height != undefined) options.height = height; SP.SOD.executeFunc(
12 'sp.ui.dialog.js',
13 'SP.UI.ModalDialog.showModalDialog',
14 function () {
15 SP.UI.ModalDialog.showModalDialog(options);
16 }); } //接收返回值方法
function dialogCallback(dialogResult, returnValue) {
//其中dialogResult=1,代表确定,dialogResult=0,代表关闭
if (returnValue != null && dialogResult == 1) { }
return;
}

2.关闭弹出框

//关闭
function closeDialog() {
window.frameElement.cancelPopUp();
}