SharePoint: Passing Parameter Data to a Modal Dialog and IE7


When calling a modal dialog in SharePoint 2010 you can pass parameter data to it as shown below;

	var dialogArgs = {
		WftForm: formName,
		WftId: workflowTypeId,
		WftColor: formColor
	};

	var dialogOptions = {
		url: "my-dialog.aspx",
		title: "Dialog Title",
		showClose: true,
		allowMaximize: false,
		autoSize: true,
		args: dialogArgs,
		dialogReturnValueCallback: onDialogClosed
	};
	SP.UI.ModalDialog.showModalDialog(dialogOptions);

And in your dialog code you can retrieve the parameter data using the following;

	var dialog = SP.UI.ModalDialog.get_childDialog();
	if (dialog != null) {
		dialogArgs = dialog.get_args();
		workflowTypeId = dialogArgs.WftId;
		workflowTypeColor = dialogArgs.WftColor;
	}

Recently when working with IE7 I found that this wouldn’t work, the value of the dialogArgs variable (above) was undefined.

Since in my code the parameter data is an object literal I’m guessing that IE7’s lack of native JSON support may be something to do with this, since it works just fine with IE8 and IE9.

One workaround is to use query string parameters appended to the dialog url, and from the dialog code to retrieve them using GetUrlKeyValue(), this is fine for simple data, but for objects it would get messy.

In this scenario another simple workaround is to retrieve the parameter data from window.frameElement;

	var dialog = SP.UI.ModalDialog.get_childDialog();
	if (dialog != null) {
		dialogArgs = dialog.get_args() || window.frameElement.dialogArgs;
		workflowTypeId = dialogArgs.WftId;
		workflowTypeColor = dialogArgs.WftColor;
	}

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

One thought on “SharePoint: Passing Parameter Data to a Modal Dialog and IE7

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s