javascript - get domain ONLY from document.referrer

you can use internally write the url to an anchor element and from that one get the smaller parts

var anchor = document.createElement("a");
anchor.href = "http://www.davidj.com/pages/flyer.asp";

console.log(anchor.protocol + "//" + anchor.host); // "http://www.davidj.com"

it is far easier then as you do not have to take care about splitting or something like that... it is quite logical... the native anchor has the same properties like window.location at least regarding the URL

EDIT: IE 6-9 adds the default port to anchor.host // "http://www.davidj.com:80


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];
}