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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -