Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get args from SP.UI.ModalDialog?

I have tried other online suggestions without success.

So...

My function opening a SharePoint dialog passes agrs into the prescribed option object, like so:

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 args BACK from the dialog, like so:

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

$(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.ModalDialog object has no get_childDialog function.

like image 758
Prisoner ZERO Avatar asked Aug 15 '12 13:08

Prisoner ZERO


1 Answers

Use var args = window.frameElement.dialogArgs;

The article I used for reference.

Live Article.

like image 74
Jaime Torres Avatar answered Oct 23 '22 02:10

Jaime Torres