3

How can i get the document.referrer.refferer I mean like the referrer of the refferer of the current document.

I used the document.referrer on my site here:

function statistics() {
  if(window.location.href.indexOf("statistics") > -1 && history.length) {
    history.back()
  } else if(window.location.href.indexOf("games") > -1 && history.length) {
    window.location.replace(document.referrer + "/../tournament.html");
  } else {
    window.location.replace("./tournaments/tournament.html");
  }
  }

The purporse is to "remember" where the user has came from.

Now there is a possibility to go to a setting site from that site where this code is. Therefore the equivalent needed code would be:

function nftStatistics() {
  if(window.location.href.indexOf("statistics") > -1 && history.length) {
    history.go(-2)
  } else if(window.location.href.indexOf("games") > -1 && history.length) {
    window.location.replace(document.referrer.referrer + "/../tournament.html");
  } else {
    window.location.replace("./tournaments/tournament.html");
  }
}

However this code does not work, because document.referrer.referrer isnt a thing. I hope you can help me and come up for a solution since i cant solve this issue on my own.

I have already tried

  1. Searching the Internet
  2. Searching the Internet for alternatives
  3. Asking friends
  • 2
    This would almost certainly be a privacy invasion: https://stackoverflow.com/questions/11556781/can-we-get-browser-history-by-using-javascript https://stackoverflow.com/questions/13369829/access-my-entire-browsing-history-via-javascript – Barry Carter Aug 14 '22 at 13:33
  • Is there any other way to do what i want to do? Any Ideas? My Main Idea is to note where i came from in the url or something but that doesnt feel clean – Sakura Queen Aug 15 '22 at 06:07

1 Answers1

0

Solution unfortionately this isnt posible for privacy reasons so i just modified the URL wile visiting the next url. The code for that looks like this:

function nftMarked() {
  if (window.location.href.indexOf("#statistics") > -1 && history.length) {
    window.location.replace("./nft.html#statistics=profile?=" + document.referrer);
  } else if (window.location.href.indexOf("#games") > -1 && history.length) {
    window.location.replace("./nft.html#games=profile?=" + document.referrer);
  } else {
    window.location.replace("./nft.html");
  }
}

going back to the 'document.referrer.referrer' looks like this now:

function nftStatistics() {
  if(window.location.href.indexOf("#statistics") > -1 && history.length) {
    history.go(-2)
  } else if(window.location.href.indexOf("#games") > -1 && history.length) {
    var url = String(window.location);
    url = url.split("=").pop();
    window.location.replace(url + "/../tournament.html")
  } else {
    window.location.replace("./tournaments/tournament.html");
  }
}

Conclusion If you ask me this solution isnt that clean and can forward your users to any other website if they edit their URL but its the only solution i came up with. So if you have any better ideas i would be very happy to hear from you.