I am trying to get the full referring url to a page via javascript.
So far the closet I have e is
var lastUrl = document.referrer;
This does not include the query attached to the url.
var lastUrl = document.URL;
returns the current URL with the querystring intact.
Is there anyway of easily obtaining the referring url along with the referring query.
I am trying to get the full referring url to a page via javascript.
So far the closet I have e is
var lastUrl = document.referrer;
This does not include the query attached to the url.
var lastUrl = document.URL;
returns the current URL with the querystring intact.
Is there anyway of easily obtaining the referring url along with the referring query.
Share Improve this question asked May 15, 2014 at 15:33 SideshowSideshow 1,3516 gold badges28 silver badges50 bronze badges 4- Could you share us an example? – naota Commented May 15, 2014 at 15:40
-
document.referrer will bring back for example
http://mydomain./paths/file.php
, this being the previous referring page where as I requirehttp://mydomain./paths/file.php?inherit=true&id=123
. Usingdocument.URL
will bring the full path but of the currently viewed page – Sideshow Commented May 15, 2014 at 15:47 - This page might help you. stackoverflow./questions/2680328/query-string-in-javascript – naota Commented May 15, 2014 at 15:54
- Thanks, but I looked at these - may be able to munge the first answer to something useful though. – Sideshow Commented May 15, 2014 at 16:07
1 Answer
Reset to default 9You cant. You can navigate user to previous page with
window.history.back();
but you will not know what url it was. You can get only this:
document.referrer
i know, it's not full query with url, but it's referrer.
P.s. Would you like, that any page would be able to check where you've been before? Some pages use authentication via url, so anyone would be able to grab those links from your browser's history.