I'm looking for something like alert()
, but that doesn't "pause" the script.
I want to display an alert and allow the next command, a form submit()
, to continue. So the page will be changing after the alert is displayed, but it won't wait till the user has clicked OK.
Is there something like this or is it just one of those impossible things?
One of the nice things about the built-in JavaScript alert is that - unlike virtually anything else in JavaScript - it's synchronous. It's completely blocking, and no other code will execute until it's been dismissed.
One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.
Add hidden div aligned with your elements and show the message on hidden div's instead of alert box.
You could do the alert in a setTimeout (which a very short timeout) as setTimeout is asynchronous:
setTimeout("alert('hello world');", 1);
Or to do it properly you really show use a method rather than a string into your setTimeout:
setTimeout(function() { alert('hello world'); }, 1);
Otherwise you open yourself up to JavaScript injection attacks. When you pass a string it is run through the JavaScript eval
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With