Possible Duplicate:
Sleep in Javascript
I want to make a sleep function in JavaScript, I have to stop any code execution before the user performs an action (like the alert() behaviour)
What I need is exactly: what should I insert here to make it work?
window.alert = function(message){
var dialog = $('<div>'+message+'</div>').dialog({
title:'Alert',
buttons:{
'Ok': function(){
$(this).dialog('close').data('open', false);
$(this).remove();
}
}
}).data('open', true);
//What to insert here?
}
jQuery deferreds are the best way to do this. It provides a nice callback framework so that its easier to maintain callbacks.
I have made a new function because some browsers may not let you redefine
alert.Then
if you want what you commented on, it would be this way.