2

The question is pretty much the same as the title.

Is there a way in Javascript to determine whether the page was opened by <a href> HTML tag or by window.location.href?

I need conditions for clearing saved states of data-table:

on reload

and

on opened via <a href> tag.

I don't want to clear saved states when opened via window.location.href.

I got one on reload:

if (performance.navigation.type == 1){
      var table = $('#categoryList').DataTable();
      table.state.clear();
      table.search("").draw(); 
      table.column( '0:visible' ).order( 'asc' ).draw();
      table.page.len(10).draw();
    }

I'm looking for another one on oponed via <a href>.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • I think this is the solution you're looking for. https://stackoverflow.com/questions/36522178/detect-if-page-was-redirected-or-loaded-directlyjavascript – Daniel Rodrigues Nov 30 '21 at 12:30
  • Thank you for the response. I have already checked with this condition if (document.referrer && !document.referrer.includes('animalCategor') || performance.navigation.type === 1) {} but what if there are multiple routes that contains "animalCategor" ? – Vishwesh Chotaliya Nov 30 '21 at 12:37
  • _"but what if there are multiple routes that contains animalCategor?"_ - well be more specific in what you want to match then? – CBroe Nov 30 '21 at 13:36
  • Yes, thanks, and if we don't want to clear saved states on a back button from anywhere if (document.referrer && !document.referrer.includes('fanPagePost') && performance.navigation.type != 2 || performance.navigation.type === 1){} it will work!. – Vishwesh Chotaliya Dec 01 '21 at 06:31

0 Answers0