sharepoint 2016 弹出新窗口并返回值的方法

来源:互联网 发布:word修改属性软件 编辑:程序博客网 时间:2024/05/17 08:48

1.创建一个ModalDialogTest的可视化webpart,代码如下:

<script>

        function OpenModalDialog(title, width, height) {

            var options = SP.UI.$create_DialogOptions();

            var options = {

                title: title,

                width: width,

                height: height,

                url: "/sitepages/test2.aspx"

            };

            options.dialogReturnValueCallback =Function.createDelegate(null, CloseCallback);

           SP.UI.ModalDialog.showModalDialog(options);

            SP.UI.ModalDialog.showModalDialog(options);

        }

        // Dialog callback

        function CloseCallback(result, retVal) {

            if (result == SP.UI.DialogResult.OK) {

                // Run OK Code

                // To be consistent with the below...

                document.getElementById('<%=CurrentText.ClientID%>').value = retVal[0];

                //close ModalDialog.

               SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancelled clicked');

                // Note that I use this.dataArray to allow theobject to be accessed throughout the code

            }

            if (result == SP.UI.DialogResult.cancel) {

                // Run Cancel Code

               SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancelled clicked');

            }

        }

    </script>

<input id="CurrentText" runat="server" type="text" />

<input id="BtnOpenModalDialog" type="button" value="打开新窗口" onclick="OpenModalDialog('弹窗新窗口',600', '600');" />


2.在sharepoint创建一个web部件页test1.aspx,存放在网站页面的文档库中,存放的路径:/sitepages/test1.aspx,并且将ModalDialogTest添加到test1.aspx页面。


3.创建一个NewDialog的可视化webpart,代码如下:


<script type="text/javascript">

        function BtnCloseFunc() {

           SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'Cancelled clicked');

        }

        function BtnCloseAndReturnValueFunc()

        {

            var returnValue = []; // array

            returnValue[0] = document.getElementById('<%=NewDialogText.ClientID%>').value;

           SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK,returnValue);

        }

    </script>

    <input id="NewDialogText" type="text" runat="server" />

    <input id="BtnCloseAndReturnValue" type="button" value="关闭并返回值" onclick="BtnCloseAndReturnValueFunc();" />

    <input id="BtnClose" type="button" value="关闭" onclick="BtnCloseFunc();" />


1 0