P.Brian.Mackey P.Brian.Mackey - 1 month ago 15
jQuery Question

Can we control the "loading" icon in the browser tab?

I have a series of AJAX calls via jQuery. When an ajax call is being performed, there is no visual indication. Normally if you click a link or otherwise some non-ajax load the browser displays a little loading icon up in the tab.

Is there any way to tell the browser to display this little icon in the tab? (There are about 30 of these calls so I hope to avoid modifying each one).

Answer Source

No, you can't tell the browser such a thing.

But you can do your own loading indicator. Include a hidden element in your markup, then use the ajaxStart and ajaxStop events to control its visibility:

$("#loading_animation").bind({
    ajaxStart: function() { $(this).show(); },
    ajaxStop: function() { $(this).hide(); }
});

ajaxStart is fired by jQuery when an ajax request is started when none others are running; ajaxStop is fired when an ajax request completes are there are no others running.