javascript - Create JS execution blocking dialogs using jQuery - Stack Overflow

I have an existing web application which uses window.showmodaldialog() to show certain forms and based

I have an existing web application which uses window.showmodaldialog() to show certain forms and based on the return value it executes some other JavaScripts

For example:

var retVal = window.showmodaldialog('...');

if (retVal==XXX)
  callXXX();
else
  callYYY();

When showModalDialog() is executed it blocks the JS execution on the main window until the modal is closed.

I am trying to replace these modal Windows with jQuery dialogs but the problem is that once the $(...).dialog().open() is executed the JavaScript execution does not wait for the dialog to be closed.

I know that there are jQuery APIs which allow me to configure a callback function but that involves a lot of changes for me. Is there anyway by which I can pause JavaScript execution until the dialog is closed (I must still be able to execute scripts from the dialog).

I have an existing web application which uses window.showmodaldialog() to show certain forms and based on the return value it executes some other JavaScripts

For example:

var retVal = window.showmodaldialog('...');

if (retVal==XXX)
  callXXX();
else
  callYYY();

When showModalDialog() is executed it blocks the JS execution on the main window until the modal is closed.

I am trying to replace these modal Windows with jQuery dialogs but the problem is that once the $(...).dialog().open() is executed the JavaScript execution does not wait for the dialog to be closed.

I know that there are jQuery APIs which allow me to configure a callback function but that involves a lot of changes for me. Is there anyway by which I can pause JavaScript execution until the dialog is closed (I must still be able to execute scripts from the dialog).

Share Improve this question edited Aug 21, 2010 at 13:20 Gert Grenander 17.1k6 gold badges41 silver badges43 bronze badges asked Aug 21, 2010 at 13:16 Vinay B RVinay B R 8,4313 gold badges32 silver badges45 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Unfortunately, no. You will need to use callback functions of some kind. 'Blocking' like this in JavaScript is a bad idea because there is only a single execution thread and JavaScript uses an Event Driven model.

You could do something like this to "wait" for the return value, but this doesn't "block" other execution at all:

var myReturn, 
myInterval = setInterval(function () {
  if (myReturn != undefined) {
    clearInterval(myInterval);
    // Rest of processing code here.
  }
}, 50);

$('myContainer').dialog(close: function () {
  myReturn = 'Dialog Closed';
}).open();

Attempting to "block" or "pause" JavaScript execution should be avoided - the language is simply not designed for it.

I'm afraid there is no way to "pause" javascript execution until you want natively.. The showModalDialog function do that because is implemented by the browser.

You can just do your "waiting" mechanism by hand, and You'd need to do the changes (as you said they are a lot, but shouldn't be plex changes).

These are the things that es to my mind now:

  • Make use of callbacks ( to me, the best by far )
  • Use setTimeout and your own mechanism, as g.d.d.c answered .
  • Use some user threads javascript library.

But if you're open to plugins, I've just found this jQuery plugin: BlockUI , and some others that maybe help you. And out there must be a few other plugins that already implement what I mentioned in the points above.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745566500a4633426.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信