javascript - get domain ONLY from document.referrer
javascript, jquery
Solution
var url = "http://www.ronniej.com/linkdes.com/?adv=267&loc=897"
var referrer = url.match(/:\/\/(.[^/]+)/)[1];
http://jsfiddle.net/hyjcD/
if (document.referrer) {
url = document.referrer;
ref = url.match(/:\/\/(.[^/]+)/)[1];
}
Problem
I would like to get ONLY the domain from the referrer urls. The referrer urls I mostly get are `http://www.davidj.com/pages/flyer.asp` & `http://www.ronniej.com/linkdes.com/?adv=267&loc=897` Whenver I get referrer urls like the above, I just want to get the domain example: http://www.davidj.com I have tried using the .split method but i am having trouble using it.