Let say, visitor visited my website example.com and then visited other website (maybe by clicking any link of my webpage or maybe manually typing to address bar) in same tab and then he pressed browser back button and came back to my website example.com
How can i detect that the user visited my site again with back button?.
I am trying
With Popstate :
window.addEventListener('popstate', function(event) {
if (event.state && event.state.source === 'example.com') {
console.log('User returned to example.com by clicking the back button');
}
});
With onpopstate
window.onpopstate = function(event) {
if (event && event.state) {
console.log('User returned to example.com by clicking the back button');
}
};
With pageshow
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
console.log('User returned to example.com by clicking the back button');
}
});
Sadly, none of these worked!!