Javascript modal dialog box - want it without cancel (X in top right corner) capability

I use a modal dialog in Javascript to create a "pop up dialog" that gets some data from the end user, using the following code:


function PopUp(url)
{  
   if (window.showModalDialog)
   {
      newwindow = window.showModalDialog(url,
          "PopUp",'dialogHeight:200px,dialogWidth:500px, status:no');
   } else {
      alert(' bad');
   }
   return false;
}

the page loaded has two button images whos onclick method I use to return to the caller....all of this works fine except that I do NOT want user to be able to hit X on right top of window so as to cancel the window and leave my code in an unknown state. Anyone know how to prevent the showing of the "X" in top right corner, or how to disbale it?
smmsmm57Asked:
Who is Participating?
 
LeeKowalkowskiCommented:
Let's look at how showModalDialog works first:

var returnValue = window.showModalDialog(url, arguments, features);

When the window closes, it returns a value.  If there is no return value set, it returns 'undefined'.

So, you can do this:
while(!showModalDialog(url, arguments, features))

Which will force the redisplay of the dialog box if it is closed using the close button.

However, this means inside your dialog box, you must make sure you are setting a return value.

E.g:
<button onclick="window.returnValue='yes';window.close()">Yes</button>
<button onclick="window.returnValue='no';window.close()">No</button>

--
Lee
0
 
hernst42Commented:
Not possible to disable the close button of the browser-popup-window. You can use the onunload function of the body to notify the open, that the windows was close without proper action like:

<script>
var action = false;
</script>
<body onunload="if(!action) window.opener.notify">

and in you onclicks for valid actions use:
onclick="action=true; ...rest of the onclick you use"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.