利用JS保持地址栏不变和语言跳转, 功能实现, 但细节不完美, 求解.
目的:
1. 利用JS实现根据浏览器的语言版本实现不同页面的请求.
2. 利用JS实现不同页面请求后, 地址栏保持不变.
index.htm代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script>
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
XMLHttpR = new XMLHttpRequest();
}else if(window.ActiveXObject){
try{
XMLHttpR = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
XMLHttpR = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
}
}
}
}
function sendRequest(url){
createXMLHttpRequest();
XMLHttpR.open("GET",url,true);
XMLHttpR.setRequestHeader("Content-Type","text/html;charset=utf-8");
XMLHttpR.onreadystatechange = processResponse;
XMLHttpR.send(null);
}
function processResponse(){
if(XMLHttpR.readyState ==4 && XMLHttpR.status == 200){
document.write(XMLHttpR.responseText);
}
}
</script>
<script>
var type=navigator.appName
if (type=="Netscape")
var lang = navigator.language
else
var lang = navigator.userLanguage
if (lang.substr(0,5) == "zh-cn")
sendRequest("http://www.xxx.com/cn.htm")
else
sendRequest("http://www.xxx.com/en.htm")
</script>
</body>
</html>
cn.htm代码如下:
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<link rel="Shortcut Icon" href="favicon.ico">
<style type="text/css">
.style1 {
text-align: center;
}
.style2 {
text-align: right;
}
</style>
</head>
<div class="style1">
<img src="images/LogoX.jpg"></div>
<p class="style1">中文页面</p>
en.htm代码如下
<head>
<meta http-equiv="Content-Language" content="EN">
<link rel="Shortcut Icon" href="favicon.ico">
<style type="text/css">
.style1 {
text-align: center;
}
.style2 {
text-align: right;
}
</style>
</head>
<div class="style1">
<img src="images/LogoX.jpg"></div>
<p class="style1">English Page</p>
基本的功能目标已经实现, 可问题是, 不同语言版本的页面在浏览器状态栏分别出现:
"正在下载图片 http://www.xxx.com/images/LogX.jpg..."
"Downloading Picture http://www.xxx.com/images/LogX.jpg..."
而实际上, 这个图片已经加载完毕了. 如果点击刷新一次,又都正常完成了?