I have a sharepoint site in which there is a javascript confirmation alert on which, on yes click, I'm showing a div which has the loading image via jquery and hiding it when the function is completed (it is a long running script). But on clicking yes, the page gets stuck for a long time and the loader image is not shown. enter image description here The code executes perfectly doing the job thereafter (I see stop script on IE and kill page on chrome sometimes).

The code for showing the div is: var newdelAAEdate = new Date(new Date().setDate(new Date().getDate() + (-7))); if (confirm('Are you sure you want to create AAE Timeslots for ' + $('#ddMonth option:selected').text() + ', ' + $('#ddYear option:selected').text() + '?\n\n Note: The time slots before ' + newdelAAEdate.toDateString() + ' will also be deleted.')) { $('#loaderDiv').show(); $("#outputWindow").css('background-color', 'white'); onClickAAE_Ts(); }
else { // Do nothing! }

I finally hide the div when the function (which has GET, POST and DELETE rest calls running synchronously) gets executed, but none of it is happening.

Note: The div shows if I debug on chrome, but somehow skips normally

1 Answer 1


The JavaScript engine (which is different in every Browser, because every vendor implements ECMAscript different) tries to optimize your code.

If your onClickAAE_Ts( ) function is doing some serious operations the DOM might not get updated until after it has finished.

Trick to force a DOM repaint could help

  $("#outputWindow").css('background-color', 'white');
  window.setTimeOut( onClickAAE_Ts , 1 ); //async wait 1 millisecond

But be aware your code will continue immediatly after it initialized that async setTimeout function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.