Skip to content
Amal Hashim
All posts
Snippet

SharePoint 2010 Modal Dialog

Open a page in a SharePoint 2010 modal dialog from JavaScript and handle the result when it closes.

1 min read#JavaScript#SharePoint#SharePoint 2010

SharePoint 2010 has a client object model, so you can call SharePoint operations from JavaScript. This code shows a page in a modal popup dialog.

js
var options = SP.UI.$create_DialogOptions();
options.width = 450;
options.height = 450;
options.url = "/_layouts/PageName.aspx";
options.showClose = true;
options.title = "Dialog Title";
options.dialogReturnValueCallback =
    Function.createDelegate(null, modalDialogClosedCallback);
SP.UI.ModalDialog.showModalDialog(options);

The handler runs when the dialog closes:

js
function modalDialogClosedCallback(result, value) {
    // Code to handle the callback
}