Jump to content
xisto Community
Sign in to follow this  
Giniu

Need Opinion - Language Redirection Script...

Recommended Posts

Hi... I wasn't there for some time but now I need opinion... I hope someone would be able to say something about my script... what should be fixed, what I can do to improve it...

it is universal language redirection script for few pages that I work on and I need it to be as good as it can be... would this be working in every browser in which scripts like that can work? If now what I should add?

(why I aded "en" and "en-US"? The script first checks if there is exact name and then it converts it to small letters and takes only two first... just in case someone would ask before finishing read...)

 <script TYPE="text/javascript"> 	 languages=new Array("pl", "en", "en-US"); 	 default_language="en"; 	 if (navigator.language)    navigator_language=navigator.language 	 else if (navigator.browserLanguage)    navigator_language=navigator.browserLanguage 	 else if (navigator.systemLanguage)    navigator_language=navigator.systemLanguage 	 else if (navigator.userLanguage)    navigator_language=navigator.userLanguage 	 else if (window.navigator.language)    navigator_language=window.navigator.language 	 else    navigator_language=default_language; 	 in_list=-1; 	 for (i=0; i<languages.length; i++)    if (languages[i]==navigator_language)   	 in_list=i; 	 if (in_list>=0)    language=navigator_language 	 else    navigator_language=navigator_language.substr(0,2).toLowerCase(); 	 for (i=0; i<languages.length; i++)    if (languages[i]==navigator_language)   	 in_list=i; 	 if (in_list>=0)    language=navigator_language 	 else    language=default_language; 	 open_site="./"+language+"/index.html"; 	 window.location.replace(open_site);  </script>
And what do you think?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.