简体   繁体   中英

Method to detect page came from back button

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
})

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM