How to Get args from SP.UI.ModalDialog?

asp.net, javascript, sharepoint, sharepoint-2010

Solution

Use `var args = window.frameElement.dialogArgs;`

The article I used for reference.

Live Article.

Problem

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.

Original source