I am developing a mobile site, keeping in mind all the leading browsers - Safari, Chrome, Dolphin, Opera.
I want to show the loading element how and when a navigation / change page / new page is requested .
I cannot use the click event for anchor tags, since there are many of them with preventDefault();.
I tried the following:
$(window).on('beforeunload', function() { ... });
But it does not work in Dolphin or Opera .
Can anyone suggest a cross-browser solution ?
-
EDIT . I understand that I didn’t ask my question very clearly, I apologize. I created a fiddle here http://jsfiddle.net/hiteshpachpor/7dadA/5/ based on the answer. This example uses bubbling events.
Now here is the problem I am facing. I would show that the loader ( $('.jacket').show();) every time the page changes / moves. But I do not want it to appear if the link is clicked; Instead, I want to perform other operations on my page. Now adding a line $('.jacket').hide();in all such actions would be sufficient, but it would not be very ideal for scaling the reasons.
That's why I evaluated the method 'beforeunload', but we were out of luck, as it is not compatible with cross-browser.
Any suggestions for resolving this issue?