0

I have tried to add multi language button to my site in the form of a select tag with options for each language which redirects to the home pages for each language.

However, this seems to work only on PC Browsers and not on Mobile browsers.

what is the problem?

Here is the my code:

 <!--Changing language client side-->
 <script type="text/javascript"> 

function Redirect_en(){
  window.location="index.html";
 } 

function Redirect_fr(){
 window.location="fr/fr-index.html";
} 

function Redirect_es(){
  window.location="es/es-index.html";
} 

function Redirect_zh(){
   window.location="zh/zh-index.html";
} 

</script>
 .
...
      <span id="lang_header_form"> 
       <form  method="POST" id="lang_form">             
           <select name="language" id="lang_select">
              <option value ="English" onclick="Redirect_en();"         selected>English</option>
              <option value = "French" onclick="Redirect_fr();">French</option>
              <option value="Spanish" onclick="Redirect_es();">Spanish</option>
              <option value="Chinese"    onclick="Redirect_zh();">Chinese</option>
          </select>
       </form>
    </span>
2
  • What actually does happen on the mobile browsers? Commented Mar 30, 2018 at 20:22
  • 2
    Welcome to Stack Overflow. Please, have a look at How to Ask and clarify your question a bit more. Commented Mar 30, 2018 at 20:22

2 Answers 2

1
<select id="Lang" onchange="changeLang(this)">
 <option value="en">English</option>
 <option value="fr">French</option>
</select>
<script>
   function changeLang(selectObject) {
     switch(selectObject.value){
        case 'en': window.location="/index.html"; break;
        case 'fr': window.location="fr/fr-index.html"; break;
      }
   }
</script>

The above example gets you the selected language on OnChange event. which should work in mobile

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

function redirect(self){
  window.location = self.value + 'index.html';
}
<select name="language" onchange="redirect(this);">
    <option value="" selected>English</option>
    <option value="fr/fr-">French</option>
    <option value="es/es-">Spanish</option>
    <option value="zh/zh-">Chinese</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.