Search code examples
jqueryurlhreflocation-href

Replace by current domain


I have a link : http://fakedomain.net/path

I want to replace dynamically the link with the current domain name like this : http://currentdomain.com/path

$('.link a').each(function(){
    this.href = this.href.replace('http://fakedomaine.net/', WHAT_GOES_HERE);
});

But I am blocked at this point


Solution

  • Try this

    this.href = this.href.replace('http://fakedomaine.net', 
    location.protocol+"//"+location.host);