Redirect Javascript语言重定向
我在哪里可以找到一个简单的javascript重定向代码,该代码将检测到的所有语言重定向到一个英语页面,除了有适当页面的意大利语之外 非常感谢诸如此类的事情 通常,我更喜欢在服务器级别重定向(例如,对于Apache,使用mod_rewrite): PS:以下是一些附加链接,以及基于语言的不同重定向选项:Redirect Javascript语言重定向,redirect,detect,country,Redirect,Detect,Country,我在哪里可以找到一个简单的javascript重定向代码,该代码将检测到的所有语言重定向到一个英语页面,除了有适当页面的意大利语之外 非常感谢诸如此类的事情 通常,我更喜欢在服务器级别重定向(例如,对于Apache,使用mod_rewrite): PS:以下是一些附加链接,以及基于语言的不同重定向选项: HTML重定向 JavaScript重定向 Apache重定向 Nginx重定向 Lighttpd重定向 PHP重定向 RubyonRails重定向 .NET重定向 Node.js重定
- HTML重定向
- JavaScript重定向
- Apache重定向
- Nginx重定向
- Lighttpd重定向
- PHP重定向
- RubyonRails重定向
- .NET重定向
- Node.js重定向
var langcodes=["fr", "es"];
// Browser Language Redirect script
// copyright 3rd January 2006, Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (with the sole exception
// of the langcodes array entries) is used without any alteration
var langCode = navigator.language || navigator.systemLanguage;
var lang = langCode.toLowerCase();
lang = lang.substr(0,2);
var dest = window.location.href;
for (i=langcodes.length-1;i >= 0; i--){
if (lang==langcodes[i]){
dest = dest.substr(0,dest.lastIndexOf('.')) + '-' + lang.substr(0,2) + dest.substr(dest.lastIndexOf('.'));
window.location.replace ?window.location.replace(dest) :window.location=dest;
}
}