Sharepoint promoted links webpart open in dialog opens the popup using SP.UI.ModalDialog.ShowPopupDialog(url)

How do I close this popup using a custom button in the popup page SP.UI.ModalDialog is null in the context of the page.

3 Answers 3


Try using commonModalDialogClose.

Create function to close popup or directly call method.

function CloseDlg() {

Or try to hide using class.


function CloseSPUIPopoup{

Use dialogReturnValueCallback option

var options = SP.UI.$create_DialogOptions();
    options.url = '/_layouts/mySolution/myPage.aspx';
    options.width = 500;
    options.height = 400;
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);

function CloseCallback(result, target) {
    //Your code
  • SP.UI.ModalDialog is undefined. SO it doesn't work
    – Jinxed
    Commented Oct 7, 2015 at 9:15
  • when you show SP.UI.ModalDialog is defined but when you try to close it is undefined! can not get. Show your code how you are using it Commented Oct 7, 2015 at 9:24
  • Can you post some of your code. And have you identify why SP.UI.ModalDialog is undefined? Because at my end its working fine. Commented Oct 7, 2015 at 10:01
  • 1
    I had to load SP.UI.Dialog.js. But after closing I want to redirect the parent page to another page. How could I do that . Do I need to pass a parameter?
    – Jinxed
    Commented Oct 7, 2015 at 10:19

Once I closed my modal in the following way

var closeLoading = function() {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
        SP.UI.ModalDialog.commonModalDialogClose(1, 1);

So write the following line of code in your button click handler.

SP.UI.ModalDialog.commonModalDialogClose(1, 1);
  • No that doesn't work. SP.UI.ModalDialog is undefined. Is it because popup has been opened using SP.UI.ModalDialog.ShowPopupDialog(url)?
    – Jinxed
    Commented Oct 7, 2015 at 7:29
  • Show your code. I mean how do you use it Commented Oct 7, 2015 at 7:36

Here is my code for a custom button, in case it helps someone.

<input type="button" value="Cancel" name="gobackbutton2" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel);" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.