日期:2014-05-16  浏览次数:20309 次

根据浏览器的语言选择不同的页面
通过js判断浏览器所用的操作系统的版本不同,进入不同的页面。比如英文操作系统进入英文页面,中文操作系统进入中文页面。网上找的
<script language=”JavaScript”>
var SysLan = window.navigator.systemLanguage; //取得浏览器版本语言
if(SysLan == "zh-cn")window.location = "index.php?id=191" //中文页面
if(SysLan == "en-us")window.location = "index.php?id=471" //英文页面
</script>

不管用啊

有没有更好的代码?谢谢大家

------解决方案--------------------
JScript code
function getLang(callback) { 
//debugger; 
var node = document.createElement("script"); 
if (node.addEventListener) { 
    node.addEventListener("load", callback, false); 
} 
else { 
node.onreadystatechange = function() { 
if (this.readyState == "loaded") 
callback.call(this); 
} 
}
var wn=window.navigator;
if (wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") { 
node.type = "text/javascript"; 
node.src = "http://counter.csdn.net/a/js/AreaCounter.js"; 
} 
else if (wn.systemLanguage=="zh-tw" || wn.language=="zh-TW") { 
node.type = "text/javascript";
node.src = "http://counter.csdn.net/a/js/AreaCounter.js"; 
alert('tw');
} 
else if (wn.systemLanguage=="en" || wn.language=="zh-EN") { 
alert('en');
node.src = "http://counter.csdn.net/a/js/AreaCounter.js"; 
} 
document.getElementsByTagName("head").item(0).appendChild(node); 
node = null; 
 
}

------解决方案--------------------
JScript code

var SysLan = window.navigator.systemLanguage;
if(SysLan == "zh-cn")window.location = "http://www.baidu.com";
if(SysLan == "en-us")window.location = "index.php?id=471"; 
// JS代码是没问题的
你的location路径不对  应该是绝对路径

------解决方案--------------------
var wn=window.navigator;
if (wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") { 
window.location.href = "index.php?id=191";
}else if (wn.systemLanguage=="en" || wn.language=="zh-EN") { 
window.location.href = "index.php?id=471";
} else{
window.location.href = "index.php?id=191";//默认中文页面
}
 

------解决方案--------------------
一般都是浏览器自己判断的
------解决方案--------------------
mark
------解决方案--------------------
mark it
------解决方案--------------------
Request.ServerVariables("OS");
------解决方案--------------------
探讨
var wn=window.navigator;
if (wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") {
window.location.href = "index.php?id=191";
}else if (wn.systemLanguage=="en" || wn.language=="zh-EN") {
window.location.href = "index.php?id=471";
} else{
window.location.href = "index.php?id=191";//默认中文页面
}



------解决方案--------------------
Request.ServerVariables("http_accept_language")
------解决方案--------------------
楼主可以在不同的浏览器下运行以下脚本看看结果:

JScript code

<script type="text/javascript">
document.write(navigator.browserLanguage+'<br>');
document.write(navigator.platform+'<br>');
document.write(navigator.cookieEnabled+'<br>');
document.write(navigator.cpuClass+'<br>');
document.write(navigator.onLine+'<br>');
document.write(navigator.platform+'<br>');
document.write(navigator.systemLanguage+'<br>');
document.write(navigator.userAgent+'&