<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<html>
<head>
<title>获取服务器端时间并不停网页在显示上</title>
</head>
<body>
<p><ahref="http://www.studynote.cn">学习笔记</a>:<ahref="http://www.studynote.cn">http://www.studynote.cn</a></p>
<spanid="spnTime"></span>
<scriptlanguage="javascript">
functioncreateXMLHttpRequest(){
varrequest=false;
if(window.XMLHttpRequest){
request=newXMLHttpRequest();
if(request.overrideMimeType){
request.overrideMimeType('text/xml');
}
}elseif(window.ActiveXObject){
varversions=['Microsoft.XMLHTTP','MSXML.XMLHTTP','Microsoft.XMLHTTP','Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP'];
for(vari=0;i<versions.length;i++){
try{
request=newActiveXObject(versions[i]);
if(request){
returnrequest;
}
}catch(e){
//alert(e.message);
}
}
}
returnrequest;
}
varhttp=createXMLHttpRequest();
http.open("HEAD",".",false);
http.send(null);
varcurDate=newDate;
varoffsetTime=curDate-Date.parse(http.getResponseHeader("Date"));
setInterval(function()
{
curDate.setTime(newDate-offsetTime);
document.getElementById("spnTime").innerHTML=curDate.toLocaleString();
},1000);
</script>
</body>
</html>
<html>
<head>
<title>获取服务器端时间并不停网页在显示上</title>
</head>
<body>
<p><ahref="http://www.studynote.cn">学习笔记</a>:<ahref="http://www.studynote.cn">http://www.studynote.cn</a></p>
<spanid="spnTime"></span>
<scriptlanguage="javascript">
functioncreateXMLHttpRequest(){
varrequest=false;
if(window.XMLHttpRequest){
request=newXMLHttpRequest();
if(request.overrideMimeType){
request.overrideMimeType('text/xml');
}
}elseif(window.ActiveXObject){
varversions=['Microsoft.XMLHTTP','MSXML.XMLHTTP','Microsoft.XMLHTTP','Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP'];
for(vari=0;i<versions.length;i++){
try{
request=newActiveXObject(versions[i]);
if(request){
returnrequest;
}
}catch(e){
//alert(e.message);
}
}
}
returnrequest;
}
varhttp=createXMLHttpRequest();
http.open("HEAD",".",false);
http.send(null);
varcurDate=newDate;
varoffsetTime=curDate-Date.parse(http.getResponseHeader("Date"));
setInterval(function()
{
curDate.setTime(newDate-offsetTime);
document.getElementById("spnTime").innerHTML=curDate.toLocaleString();
},1000);
</script>
</body>
</html>