开发者

Select country and language in HTML

I'm currently building my site, I want to know how to do this...

Basically, when your press that country, it ask for the language available to you, and then it will redirect to 开发者_StackOverflow社区that language page.

How could I do that? like airlines website, you choose a country, then language and then it directs to that language page?


This will usually require some server-side processing like PHP. When the user selects a language from the form, the language choice is stored in the session and recalled on each page load.

Then you would typically have internationalization strings in your web application. The chosen language is used to select the correct i18n strings from the index.

Using plain html only, with no server-side processing, the language selection form would simply (possibly via javascript) redirect to a document root for the language. This requires you to have a full site coded in each language.

http://www.example.com
http://www.example.com/en/
http://www.example.com/de/


You could do this in many different ways.

Here's a simple way to do it:

Have a bunch of links, each a different country. When you click on one, such as:

<a href="#" onclick="getLanguages('france')" >France</a>

This will call the JavaScript Function 'getLanguages()' shown here:

<script>
function getLanguages(country){
    if(country == "france"){
        document.getElementById("languages").innerHTML = "<a href='/french.html'>French</a><a href='/english.html'>English</a><a href='/german.html'>German</a>";
    }else if(country == "china"){
        document.getElementById("languages").innerHTML = "<a href='/chinese.html'>Chinese</a><a href='/english.html'>English</a><a href='/japanese.html'>Japanese</a>";
    }
}
</script>

Obviously you'd have many more if statements for each country represented. This will basically modify an element with the ID of "languages":

<div id="languages"></div>

to include the possible languages for that country. Then when a user clicks on one of those links, it will take them to the correct page!

Hope this helps and good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜