When a window.alert() is called, the script shouldnt wait for the user input(clicking ok for example), it should continue.
How could I achieve that without using the setTimeout() function?
this.alert('Window')
console.log('Continue here, dont wait for user input on the "Window"')
3 Answers 3
No. JavaScript is single threaded. You simply can't. Unless the user input hook is completed, thread pauses there.
You can just tweak/have the DOM look like an alert with styling (weird but ok).
Comments
The alert function will pause any further execution of javascript until the user clicks the OK button because the code all runs in a single thread.
You may find this question useful as it addresses the precise problem you are trying to overcome.
Comments
Since JavaScript runs on single thread, alert/prompt/confirm will pause the execution until response is received from user.
But there are ways you can prevent this:- 1. Use custom UI instead of browser's. 2. By using WebWorkers API 3. By using setTimeout/setInterval 4. By using requestNextFrame function
alertis blocking.. Use some custom UI to display alert instead ofwindow.alertmodal boxtake a look at that topic.console.time("alert"); alert("...waiting"); console.timeEnd("alert");If you cannot block, the measured duration should be like < 1ms