js获取response header信息 和 获取User-agent的 方法


<!DOCTYPE html>
<html>
<head>
<script>

function getInfo()
{
	// 获取User-agent的 方法
	alert(navigator.userAgent);
	
	// 获取response header信息
	if (window.XMLHttpRequest) {
	  // code for Firefox, Mozilla, IE7, etc.
	  xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	  // code for IE6, IE5
	  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp != null) {
	  xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
		  // 4 = "loaded"
		  if (xmlhttp.status == 200) {
			// 200 = "OK
			alert(xmlhttp.getAllResponseHeaders());
		  } else {
			alert("Problem retrieving data:" + xmlhttp.statusText);
		  }
		}
	  };
	  xmlhttp.open("GET", document.location.href, true);
	  xmlhttp.send(null);
	} else {
	  alert("Your browser does not support XMLHTTP.");
	}
}
</script>
</head>
<body>
<button onclick="getInfo()">Get header information</button>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/shihongji/article/details/81102152
今日推荐