javascript 如何从 SP.UI.ModalDialog 获取参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11970048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:55:29  来源:igfitidea点击:

How to Get args from SP.UI.ModalDialog?

javascriptasp.netsharepointsharepoint-2010

提问by Prisoner ZERO

I have tried other online suggestions without success.

我尝试了其他在线建议但没有成功。

So...

所以...

My function opening a SharePoint dialog passes agrsinto the prescribed optionobject, like so:

我打开 SharePoint 对话框的函数传递agrs给指定的option对象,如下所示:

SETTING UP THE DIALOG:
Nothing magical here...

设置对话:
这里没有什么神奇的......

    function openEmailDialog() {
        var options = SP.UI.$create_DialogOptions(),
            url = '../Pages/EmailDocument.aspx';

        options.title = "Email Documents";
        options.width = 1024;
        options.height = 400;
        options.allowMaximize = false;
        options.url = url;
        options.args = {  DidYouGetThis: true };

        SP.UI.ModalDialog.showModalDialog(options);
    };

Next...

下一个...

Upon opening the target URL, most online examples recommend the following JavaScript to extract the argsBACK from the dialog, like so:

打开目标 URL 后,大多数在线示例都推荐使用以下 JavaScriptargs从对话框中提取BACK,如下所示:

GETTING THE ARGS:
Remember, this is JavaScript in a new page which was just opened as a dialog...

获取参数:
请记住,这是一个新页面中的 JavaScript,该页面刚刚作为对话框打开......

$(document).ready(function () {
    // This fails because "get_childDialog" doesn't exist
    var args = SP.UI.ModalDialog.get_childDialog().get_args();
});

This fails because the SP.UI.ModalDialogobject has no get_childDialogfunction.

这将失败,因为该SP.UI.ModalDialog对象没有get_childDialog功能。

回答by Jaime Torres

Use var args = window.frameElement.dialogArgs;

利用 var args = window.frameElement.dialogArgs;

The article I used for reference.

我用来参考的文章

Live Article.

直播文章