html - URL with domain substitution in javascript -
we have website, www.domain.com, want publish in other languages fr.domain.com, jp.domain.com, etc. each language subdomain separately managed site, not true multi-lingual system. want able have common chunk of code on top can link between same page on different language domains.
specifically, i'd have link of language links along top this:
french | japanese
now, suppose user on english site on page www.domain.com/a/b/c.html
i language links on top automatically written as
<a href='http://fr.domain.com/a/b/c.html'>french</a>| <a href='http://jp.domain.com/a/b/c.html'>japanes</a>| ...etc...
this easy using server-side techniques need can done purely html and/or javascript (i.e., little chunk of html and/or javascript can inserted via richtext editor of content management system).
thanks suggestions!
get current location
document.location.href
inject correct language
function makelink(lang) { return document.location.href.replace(document.location.hostname, lang + "." + document.location.hostname) } ... var fr_link = makelink("fr"); // french link
use string link.
js fiddle http://jsfiddle.net/cvbk4/
this more enough work out rest.
Comments
Post a Comment