6

I made a method to show a loading indicator at the bottom of the page when a link is clicked.

When someone hits the back button, it doesn't refresh the page content of course thus showing the loading area.

Is there a way to detect whether the page came from a redirection to fire a method to remove the loading indicator?

Kinda like so:

function cameFromeBackButton(){
    //hide loading indicator
}

OR is it a way to stop the back button and fire a method instead? like so:

function  backButtonClicked(){
    //do stuff instead of going back
}

EDIT: This is pretty much how the area is being called

$('.link').click(function(){
 //make loading area
 $('container').append(loadingAreaString)

 //grab the href and goto page
 window.location.href = $(this).attr('href');

 return false
})
Sebas
  • 21,192
  • 9
  • 55
  • 109
  • Can you just prevent the cached version of the page showing or do you WANT the cached copy to show but still fire certain things? If so http://blog.55minutes.com/2011/10/how-to-defeat-the-browser-back-button-cache/ – Eli Gassert Nov 16 '12 at 20:16
  • Seems like a sever side solution right? In my case this all needs to be client side. Sorry for not specifying. –  Nov 16 '12 at 20:28
  • How is the function that shows the loading incicator called? – Wolfgang Stengel Nov 16 '12 at 20:57

1 Answers1

1

You can transfer from server some token and store it in cookie or local storage. When stored token is different from token embedded in page - this means page was loaded from server, if values are equal - this means page was served from cache (or from back button).

Ivan Solntsev
  • 2,081
  • 2
  • 31
  • 40
  • Tried to do that but it doesn't read the storage when I hit back. –  Nov 19 '12 at 17:45
  • here is answer to how force JS run after back button http://stackoverflow.com/questions/2638292/after-travelling-back-in-firefox-history-javascript-wont-run – Ivan Solntsev Nov 19 '12 at 18:01