Skip to content

SharePoint JavaScript Dialog Handling

Detailed post: SharePoint: How to close a Modal Dialog Window

Some sample JavaScript code:

function showUserPolicyDialog() {
    var options = SP.UI.$create_DialogOptions();
    options.title = Res.userPolicyDialogTitle;
    options.autoSize = true;
    options.showClose = false;
    options.allowMaximize = true;
    options.url = SP.Utilities.Utility.getLayoutsPageUrl("UserPolicyRequestPage.aspx?isDlg");
    options.dialogReturnValueCallback = showUserPolicyDialogCallback;

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

function showUserPolicyDialogCallback(returnValue, dialogResult) {
    switch (returnValue) {
        case SP.UI.DialogResult.OK:
            SP.UI.Notify.addNotification(Res.userPolicyHasBeenAccepted);
            break;
        default:
            // redirect to the start page of the intranet
            window.location = "http://intranet";
            break;
    }
}

function userPolicyClick(accepted) {
    if (accepted) {
        window.frameElement.commonModalDialogClose(1, 'Closed with OK result');
    } else {
        window.frameElement.commonModalDialogClose(0, 'Closed with Cancel result');
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

By transmitting your comment you agree to our mentioned privacy policy content.

ten − 9 =