Is there any way to detect if current page came from back button?
I want to load data from cookie only if current page came from back button.
In addition to @Radderz answer, I had to add setTimeout
to make their solution work in chrome 83. Otherwise, I would only see 'First time load' alert.
document.addEventListener('DOMContentLoaded', function () {
var ibackbutton = document.getElementById("backbuttonstate");
setTimeout(function () {
if (ibackbutton.value == "0") {
// Page has been loaded for the first time - Set marker
ibackbutton.value = "1";
alert('First time load');
} else {
// Back button has been fired.. Do Something different..
alert('Previously loaded - Returned from Back button');
}
}, 200);
}, false);