Display confirmation box with yes or no option before closing dialog window in jquery

I have a close button on my jquery dialog window, when I click on this, we should show confirmation box with message "Do you want to close this window " (Yes/No options) if user selects "Yes" then we need to close the dialog, if user selects "No" it should n't close the dialog and stays as it is..

How we can write this ?

Thanks for everybody's help here.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In your close code

r=confirm("Are you sure you want to close this?");
// Close
else {

Open in new window

RobOwner (Aidellio)Commented:
Here is the jquery for this.  I've added a button and you capture the beforeClose event.


$(function() {
  $( "#dialog-modal" ).dialog({
    height: 140,
    modal: true,
    buttons: [{ 
      text: "Close", 
      click: function() { 
        $( "#dialog-modal" ).dialog( "close" ); 
    beforeClose:  function( event, ui ) {
      if (!confirm("Do you want to close this window")) {
        return false;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
Please explain the B grade. See here for how to grade the solutions
RNithikAuthor Commented:
can you change it to A grade.. now i understand how grade it works.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.