网页获取网络时间

	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,"网络时间")
			})
posted @ 2024-05-13 16:16  橙云生  阅读(15)  评论(0编辑  收藏  举报