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.
However, since you can use javascript on website2, you could get the referrer ( document. referrer ) and add it to the url of the pixel you get. For example: var referer = document.
document. referrer gives you the URI of the page that linked to the current page. This is a value that's available for all pages, not just frames. window. parent gives you the parent frame, and its location is its URI.
If you want to go to the previous page without knowing the url, you could use the new History api. history. back(); //Go to the previous page history. forward(); //Go to the next page in the stack history.go(index); //Where index could be 1, -1, 56, etc.
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];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With