Created
March 24, 2016 18:20
-
-
Save benmezger/21508a9fdf57c997ecf9 to your computer and use it in GitHub Desktop.
Dynamic URL using javascript (for subdomains with different tld)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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