0

I have a JavaScript event listener function that waits for a user to click on any link then shows a loading box then progresses onto next page.

If a user then clicks the back button it still shows the loading box? Is there a way I can remove it without having to force refresh?

function loading_show() {
    document.getElementById("loading").removeAttribute("style");
}

// Function to add event listener to t
function load() { 
  var el = document.getElementsByTagName("a");
  for (var i = 0; i < el.length; i++)
  {
    el[i].addEventListener("click", loading_show, false);
  }
} 

function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // do stuff
  load();
};

var _timer = setInterval(function() {
  if (/loaded|complete/.test(document.readyState)) {
    clearInterval(_timer);
    init(); // call the onload handler
  }
}, 10);

PS. I'm developing for a mobile environment and I don't wish to use jQuery so don't suggest it please.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Steven
  • 13,250
  • 33
  • 95
  • 147

1 Answers1

0

You can try catching it with the "beforeunload" event.

Here's how to use it:

catching beforeunload confirmation canceled?

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176