Question: I have a SP UIModal Pop-Up, in which I want show Alert to user when click on [X].
How can i do this in SPD 2013

Answer: 
use option property of ModalDialog **dialogReturnValueCallback**

```
var options = {
    url: "/_layouts/myPage.aspx" ,
    dialogReturnValueCallback: function (dialogResult,returnValue )
    {
       if (dialogResult == SP.UI.DialogResult.cancel)//when user click on [X]
           alert ('popup canceled')
    }
};

SP.UI.ModalDialog.showModalDialog(options);

```
This code work for me :

```
function fAddOnCloseHandler()
{
    var oCloseButton = $("a[id^='DlgClose']");

    $clearHandlers(oCloseButton.get(0));

    $(oCloseButton).on("click", function (event) { fyourFun(event)} );
}   

_spBodyOnLoadFunctionNames.push( ExecuteOrDelayUntilScriptLoaded(fAddOnCloseHandler, "SP.js") );

```