How to get the parts of a url using document.referrer?

javascript

Solution

You can create an a element with the referrer as its url.

a elements (with hrefs) can act like location objects

var a=document.createElement('a');
a.href=document.referrer;
alert([a.protocol,a.host,a.pathname].join('\n'));
a='';

Problem

I need to use `document.referrer` to get the previous URL I also need to be able to get the parts of the URL like: ``` window.location.protocol window.location.host window.location.pathname ``` but I can't figure out how to do it with `document.referrer`. Anyone got any ideas?

Original source

Related problems