JSFiddle - React, Tailwind, and code Playground
by Anov Siradj
HTML
<a href="http://fiddle.jshell.net">link dalam</a>
<a href="google.com">ke google</a>
<a href="//google.com">ke google</a>
<a href="http://google.com">ke google</a>
<a href="contact">kontak</a>
<pre id="whutt"></pre>
JavaScript
var whutt = document.getElementById('whutt');
var rx = new RegExp(location.hostname);
function w(m) {
whutt.innerHTML += m+"\n";
}
w("alamat: "+location.hostname+"\n");
for(var i = 0; i < document.links.length; i++) {
var ket = "dalam";
if(!rx.test(document.links[i].href)) {
ket = "luar";
var jad = "gen/"+encodeURIComponent(document.links[i].href);
document.links[i].href = jad;
}
w(ket+": "+document.links[i].href);
w("^ menjadi: "+document.links[i].href+"\n");
}