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 :

 1 function showDialog(title,url,width,height) {
 2     var options = {
 3         url:url,
 4         args: 7,
 5         title: title,
 6         dialogReturnValueCallback: dialogCallback
 7     };
 8     if (width != undefined) options.width = width;
 9     if (height != undefined) options.height = height;
10  
11     SP.SOD.executeFunc(
12      'sp.ui.dialog.js',
13      'SP.UI.ModalDialog.showModalDialog',
14      function () {
15          SP.UI.ModalDialog.showModalDialog(options);
16      });
17    
18 }
19 
20 //接收返回值方法
21 function dialogCallback(dialogResult, returnValue) {
22     //其中dialogResult=1,代表确定,dialogResult=0,代表关闭
23     if (returnValue != null && dialogResult == 1) {
24     
25     }
26     return;
27 }

 

2.关闭弹出框

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

 

posted @ 2014-07-08 15:32  荡来荡去(allen)  阅读(1070)  评论(0编辑  收藏  举报