There is a new way to do this. It has been added to HTML 5 and is base
.
base
tells the browser that all urls that are not absolute begin in this url. You can only have 1 per page, the others will be ignored.
An example would look like this:
<base href="http://pt.stackoverflow.com">
<a href="/questions/tagged/javascript+html">Tag JavaScript</a>
If there are different sites and you need to change only in some elements you can do this:
var site = 'http://meusite.com';
var ancoras = document.querySelectorAll('.recommendation-shelf a');
[].forEach.call(ancoras, function(a) {
var href = a.getAttribute('href').split('/').filter(Boolean);
a.href = [site].concat(href).join('/');
// isto é só para o exemplo
a.innerHTML = a.href;
});
a {display: block;}
<a href="/questions/tagged/javascript+html">Tag JavaScript</a>
<div class="recommendation-shelf">
<a href="questions/tagged/javascript">Tag JavaScript</a>
<a href="/questions/tagged/html">Tag HTML</a>
</div>