5

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.

10

Try using commonModalDialogClose.

Create function to close popup or directly call method.

function CloseDlg() {
   SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel);
}

Or try to hide using class.

$('.CloseSPPopUp').click(function(){
   window.top.CloseSPUIPopoup();
});

function CloseSPUIPopoup{
   $(".ms-dlgContent").hide();
}

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);
    SP.UI.ModalDialog.showModalDialog(options);


function CloseCallback(result, target) {
    //Your code
}
  • SP.UI.ModalDialog is undefined. SO it doesn't work – Harshini Hegde Oct 7 '15 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 – Atish Dipongkor - MVP Oct 7 '15 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. – Kaushal Khamar Oct 7 '15 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? – Harshini Hegde Oct 7 '15 at 10:19
2

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)? – Harshini Hegde Oct 7 '15 at 7:29
  • Show your code. I mean how do you use it – Atish Dipongkor - MVP Oct 7 '15 at 7:36
0

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, privacy policy and cookie policy

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