When using alert or confirm in Javascript, the browser is forced into a synchronous process where everything (even the loading of another page) halts until the user dismisses the dialog.
I was wondering if there was any other way to force the browser to halt/pause using JS or jQuery.
I looked at similar questions such as:
How to force javascript function execute synchronously/sequentially?
How to make jQuery ui dialog box halt browser processing like an alert or confirmation box?
Getting synchronous behavior in javascript?
...but none of the answers seem to address the issue head on. If there is not a way to do it, I will fully accept that as an answer.
When using alert or confirm in Javascript, the browser is forced into a synchronous process where everything (even the loading of another page) halts until the user dismisses the dialog.
I was wondering if there was any other way to force the browser to halt/pause using JS or jQuery.
I looked at similar questions such as:
How to force javascript function execute synchronously/sequentially?
How to make jQuery ui dialog box halt browser processing like an alert or confirmation box?
Getting synchronous behavior in javascript?
...but none of the answers seem to address the issue head on. If there is not a way to do it, I will fully accept that as an answer.
Share Improve this question edited May 23, 2017 at 10:26 CommunityBot 11 silver badge asked Feb 13, 2013 at 15:35 MaxxMaxx 4,0828 gold badges34 silver badges38 bronze badges 10- 1 I think you mean "modal", not "synchronous". However, I think you need to explain your problem a bit more. Why do you want to prevent user interaction with the page? Are you using a custom dialog or something? – RB. Commented Feb 13, 2013 at 15:37
- 3 There is no way to do it in a modern browser without causing a "stop this script" dialog. – Kevin B Commented Feb 13, 2013 at 15:37
- 2 Why would you ever want to do this? Give us an example on how you intend to use this, and it gets a little easier! – adeneo Commented Feb 13, 2013 at 15:37
- 2 I wonder why, when so many developers have worked on ways to STOP JavaScript from freezing the browser, newer developers still ask us for ways to "enable" this again. – Blazemonger Commented Feb 13, 2013 at 15:40
-
1
Actually, even
alert()
does not halt everything – Bergi Commented Feb 13, 2013 at 15:42
1 Answer
Reset to default 2No, there's currently no cross browser way to force an asynchronous function to execute synchronously.
However you may make use of continuations to write asynchronous code in a synchronous manner.
Read the following answer for more details: https://stackoverflow./a/14809354/783743
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309502a4621916.html
评论列表(0条)