Created
August 18, 2015 14:24
-
-
Save giladaya/dd4e761ce20a4da802c8 to your computer and use it in GitHub Desktop.
if we are on a subdomain, change links on page that point to the main domain to point to the same path in the subdomain
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
(function subdomain() { | |
var hostParts = location.host.split('.'); | |
if (hostParts.length < 3) { | |
return; | |
} | |
var subdomain = hostParts[0]; | |
var domain = hostParts.slice(-2).join('.'); | |
var a = document.getElementsByTagName('a'); // grab every link on the page | |
var prefix = 'http://'+domain; | |
for (var i = 0; i < a.length; i++) { | |
var href = a[i].href; | |
if(href.indexOf(prefix) == 0) { | |
a[i].href = href.replace(domain, location.host); | |
console.log(a[i].href); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment