[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5122
  • Last Modified:

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?
0
smmsmm57
Asked:
smmsmm57
2 Solutions
 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now