const getNetTime = () => {
return new Promise((resolve, reject)=> {
var xhr = new XMLHttpRequest();
if( !xhr ){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("HEAD",location.href,true);
xhr.onreadystatechange=function(){
if( xhr.readyState == 4 && xhr.status == 200 ){
resolve(xhr.getResponseHeader("Date"));
}
}
xhr.send(null);
})
}
getNetTime().then(res => {
console.log(res,"网络时间")
})
标签:resolve,网页,xhr,getNetTime,res,网络,获取,new
From: https://www.cnblogs.com/chengyunshen/p/18189456