I have a button that performs heavy calculations, and between the steps of the calculation I want to refresh the page.
JavaScript:
.on('click', function() { // compute something jQuery('#page') .trigger('pageshow') ; // compute something jQuery('#page') .trigger('pageshow') ; // compute something }
This, unfortunately, does not work, because pageshow -event is launched after the completion of .on(click) .
Is it possible to force execution of .trigger(...) ?
JavaScript is an ugly solution:
.on('click', function() { // compute something window.setTimeout(function() { // compute something jQuery('#page') .trigger('pageshow') ; window.setTimeout(function() { // compute something jQuery('#page') .trigger('pageshow') ; }, 1); }, 1); }
An ugly solution will work, but actually a pretty ugly one. It is also necessary to check whether the .on('click', ...) -event is fully computed at startup.
JavaScript is a prettier but still ugly solution:
var functionFirst = function() { // compute something jQuery('#page') .trigger('pageshow') ; window.setTimeout(functionSecond, 1); }; var functionSecond = function() { // compute something jQuery('#page') .trigger('pageshow') ; window.setTimeout(functionThird, 1); }; var functionThird = function() { // compute something jQuery('#idJqGame') .trigger('pageshow') ; }; window.setTimeout(functionFirst, 1);
A more beautiful, but still ugly solution basically does the same thing as an ugly one - it’s just easier to read, and therefore I don’t know it yet.