Skip to content

Instantly share code, notes, and snippets.

@rhumlover
Created April 29, 2013 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhumlover/5480670 to your computer and use it in GitHub Desktop.
Save rhumlover/5480670 to your computer and use it in GitHub Desktop.
var _embedder = (function(doc) {
var referrer = doc.referrer,
anchor = doc.createElement('a'),
res = [referrer];
/*
Two different ways to extract domain from url:
- for only one part, we can use a fast regexp: referrer.match(/:\/\/(.[^/]+)/)[1])
- for 2+ parts, create manually a '<a>' tag, set his href to the referrer url, and
then we can access to several url infos: protocol, hostname, port...
(@see https://gist.github.com/jlong/2428561)
*/
anchor.href = referrer;
res.push(anchor.protocol + '//' + anchor.hostname);
return res.join(' | ');
}(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment