I am trying to wirte a refresh condition if the jquery dialogs are not open. Need fresh set of eyes as it does not seem to work. Code looks like that:
if(!$('#add_note-dialog').dialog("isOpen")) {
setTimeout(function() { location.reload() }, 3000);
}
The setTimeout function by itself works perectly, when I check the condition with firebug console, it shows proper status, but when I put it in <script> … it simply does not work or when I remove the “!” condition, it refreshes all the time even when the dialog is closed.
Any ideas?
The code in your question basically amounts to:
I think you’re looking for:
Or maybe even:
The first case can be implemented with setInterval():
The second case is a little trickier, as it requires binding to the dialogopen and dialogclose events, and keeping track of the timer id, e.g. with data(). We also only need a one-shot timer since it will either fire and refresh the page, or be canceled, so setTimeout() will suffice: