Method to detect page came from back button
Asked Answered
P

1

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
})
Phyletic answered 16/11, 2012 at 20:10 Comment(3)
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 blog.55minutes.com/2011/10/…Jodoin
Seems like a sever side solution right? In my case this all needs to be client side. Sorry for not specifying.Phyletic
How is the function that shows the loading incicator called?Dominickdominie
A
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).

Anthropophagi answered 17/11, 2012 at 10:42 Comment(2)
Tried to do that but it doesn't read the storage when I hit back.Phyletic
here is answer to how force JS run after back button #2638792Anthropophagi

© 2022 - 2024 — McMap. All rights reserved.