Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript get the full URL that redirected to a page

javascript refereer image explained

Hi there, as you can see on the image, in my webpage I have several pages that can redirect to the same page. On the example, both pages:

example.com/content.html -> example.com/news.html
example.com/files/actual.html -> example.com/news.html

I want to enable a button on the page example.com/news.html which goes back to the full source refereer url

So for example, if user A got redirected to example.com/news.html through example.com/content.html his Go back button should point to the source URL -> example.com/content.html

I have tried the JS property

var referrer = document.referrer;
console.log(referrer);

But It only returns the domain name example.com and not the full URL example.com/content.html

Any thank is appreciated.

like image 728
PythonicExperience Avatar asked Oct 24 '25 05:10

PythonicExperience


1 Answers

It depends on what you need. If you always have a redirection you can use :

window.history.go(-2);

Otherwise, you may have to manipulate the parameter using history informations.

Full documentation : https://developer.mozilla.org/en-US/docs/Web/API/History_API

like image 103
KBell Avatar answered Oct 26 '25 19:10

KBell