jquery - Is there a way to force synchronous behavior in JavaScript like the alert() function does? - Stack Overflow

When using alert or confirm in Javascript, the browser is forced into a synchronous process where every

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
 |  Show 5 more ments

1 Answer 1

Reset to default 2

No, 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信