0

I am wanting to trigger a function that will display all events but only when the user comes from a URL with /events/ in it.

Right now I am using referrer to take the user back to the page and to scroll to the last event they clicked on. But if the event they clicked on has to be loaded by clicking 'view more' it will just scroll to the bottom of the page. I need all the events to collapse when the user hits the return button.

Any help is much appreciated!

2 Answers2

0

You can achieve what you're trying to do with localStorage:

if(!!localStorage.getItem("isEventsInPath")) {
 // user came from /events
}


var isEventsInPath = document.location.pathname.includes("/events/");
localStorage.setItem("isEventsInPath", isEventsInPath);
// keep the order intact!
mehulmpt
  • 15,861
  • 12
  • 48
  • 88
0

You can use the following to parse the URL and call your function:

$(document).ready(function(){
    if(document.location.pathname.includes("/events"))
    {
      //CALL YOUR FUNCTION
    }
});

This parses the path name and checks if /events exists in it.

Shakti Phartiyal
  • 6,156
  • 3
  • 25
  • 46