Was the page navigated to using back or forward button?

2021-01-12 / mgrubinger / 0 reactions

window.performance.getEntriesByType("navigation")[0].type === "back_forward";

This is how to detect if a page was loaded because the user navigated via back or forward buttons.

Possible values:

  • back_forward if the navigation happened because of a back or forward navigation
  • navigate if the navigation happened because of a regular navigation event (like clicking a link).
  • reload after reloading the page
  • prerender if the navigation has happened during a prerender hint

See PerformanceNavigationTiming.type on MDN

Leave a reaction if you liked this post! 🧡
Leave a new comment