Skip to content

Instantly share code, notes, and snippets.

@benmezger
Created March 24, 2016 18:20
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 benmezger/21508a9fdf57c997ecf9 to your computer and use it in GitHub Desktop.
Save benmezger/21508a9fdf57c997ecf9 to your computer and use it in GitHub Desktop.
Dynamic URL using javascript (for subdomains with different tld)
<pre id="bar"><a id="blog">BLOG</a> XOR <a id="about" title="">ABOUT</a> XOR <a id="code">CODE</a> XOR <a id="photos" title="">PHOTOS</a></pre></td></tr>
<script>
function makeUrl(_id){
var protocol = window.location.protocol;
var url = window.location.host.replace("www.", "");
var new_url = protocol + "//" + _id + "." + url;
document.getElementById(_id).setAttribute("href", new_url);
}
makeUrl("blog");
makeUrl("about");
makeUrl("code");
makeUrl("photos");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment