0

I have a finger swipe js script with sessionStorage.

let touchstartX = 0;
let touchendX = 0;

function checkDirection() {
  if (touchendX < touchstartX && !sessionStorage.getItem('firstTime')) {
    window.location.href = '/';
    sessionStorage.setItem('firstTime', 'true');
  }
}

document.addEventListener('touchstart', (e) => {
  touchstartX = e.changedTouches[0].screenX;
});

document.addEventListener('touchend', (e) => {
  touchendX = e.changedTouches[0].screenX;
  checkDirection();
});

What I need is to set this script activated on the home page just when you come back on it from other internal pages and not on the first homepage load.

Anyone has some suggestions, please? Thank you very much!

Joshua
  • 3,055
  • 3
  • 22
  • 37
WhoAmI
  • 33
  • 5
  • Can't you also use sessionStorage to flag other internal pages visit and only run this script if your sessionStorage has the correct data ? – Axnyff Mar 28 '23 at 17:19
  • Could you explain more as to *why* you chose this approach? What is there on the second load that isn't there on the first? – Emiel Zuurbier Mar 29 '23 at 08:04

0 Answers0