0

I have a var that captures the referring URL:

$(document).ready(function() {
   var referrer =  document.referrer;
   console.log(referrer);
});

Assuming the url is http://www.example.com/this/is/my/path how can I set referrer = /this/is/my/path where the actual host domain may be variable? E.g. I want to use this on difference domains.

Update

This answer: jquery - get url path? does not help as it's a solution that uses location.pathname.split not the referrer, and also splits the path based on a string not capturing it completely.

Community
  • 1
  • 1
alias51
  • 8,178
  • 22
  • 94
  • 166
  • possible duplicate of [jquery - get url path?](http://stackoverflow.com/questions/2668005/jquery-get-url-path) – isherwood Oct 10 '14 at 16:47
  • that's solution uses `location.pathname.split` not the referrer, and also splits the path based on a string not capturing it completely. – alias51 Oct 10 '14 at 16:48
  • really not clear what your goal is with regard to different domains. This sounds like an `X-Y` problem. What is higher level objective? – charlietfl Oct 10 '14 at 17:18
  • The process is the same for any URL. I'm not clear on how your question is different. – isherwood Oct 10 '14 at 19:08

1 Answers1

0

The window.location object has the following properties considering the exmaple referrer

document.referrer; 
"http://stackoverflow.com/questions/2668005/jquery-get-url-path#footer"

location:{

  hash: "#footer"
  host: "stackoverflow.com"
  hostname: "stackoverflow.com"
  href: "http://stackoverflow.com/questions/2668005/jquery-get-url-path#footer"
  origin: "http://stackoverflow.com"
  pathname: "/questions/2668005/jquery-get-url-path"
  port: "" 
  protocol: "http:"

}

You can use location.pathname, and the empty default http port is 80

rafaelcastrocouto
  • 11,781
  • 3
  • 38
  • 63