Why popstate doesnt fire my function when back button is clicked? (mobile ios chrome)

Viewed 1975

I'm trying to do that when the link is opened in new tab, there would able back to referrer page through back button.

const referrer = document.referrer;
const redirect = (e) => {
     if(e.state.goBack){
        window.location.href = window.location.href;
     }
 }

const _location = window.location.href
history.replaceState({goBack: true}, null, referrer);
history.pushState({}, null, _location);

window.addEventListener('popstate', redirect);

works fine in MacBook, android chrome/firefox. Only in iPhone/iPad, it doesn't work. It just returns to himself. Even if I add an alert in redirect function it doesn't show up when I click the back button in iPad chrome. :(

Feels like back button click on iPad doesn't fire redirect function.

1 Answers
Related