admin管理员组文章数量:1432620
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 badges2 Answers
Reset to default 3Unfortunately, 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.
本文标签: javascriptCreate JS execution blocking dialogs using jQueryStack Overflow
版权声明:本文标题:javascript - Create JS execution blocking dialogs using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745566500a2663792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论