1

I'm trying to refresh the parent page of a list when closing the dialog of a list item.

enter image description here

Is there a way to achieve this with javascript somehow?

I inspected the button in the DOM and tried to write a jQuery listener for the button's class, but it did not work:

$(".ms-dlgCloseBtn").click(function() {
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.Cancel);
});

Advise the best way to achieve the desired functionality.

UPDATE

The dialogs are custom WebParts that have been attached to the list. The dialogs are launched via OOB functionality. I am not manually opening the dialog.

1

Your code is not working because the event is attached only to elements that are loaded into DOM. Dialog is generated dynamically.

Hence we need jQuery to attach click event to element having style ms-dlgCloseBtn whenever it gets loaded to DOM

jQuery('.ms-dlgCloseBtn').live('click',function() {
    alert('test');
});
  • I have to use .on() since I am using > jQuery 1.9, but I am still not getting a response. $("body").on("click", ".ms-dlgCloseBtn", function () { alert("test"); }); – KidBatman Apr 22 '15 at 21:58
  • Try jQuery('.ms-dlgCloseBtn').on('click',function() { alert('test'); }); – Amal Hashim Apr 22 '15 at 22:11
  • I am still unable to launch the alert dialog per clicking the 'x' and your solution above. – KidBatman Apr 23 '15 at 15:53
  • Can anyone out there suggest a possible server side option then? – KidBatman May 4 '15 at 18:10

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.