
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>获取文档信息</title>
	</head>
	<script type="text/javascript">
		function getDocument(){
			var imgNum=document.images.length;//获取图片数量
			var linkNum=document.links.length;//获取链接数量
			var anchorNum=document.anchors.length;//统计所有锚数量
			
			var documentInfo="";
			documentInfo+="文档中所有图片数量"+imgNum +"<br/>";
			documentInfo+="文档中所有链接数量"+linkNum+"<br/>";
			documentInfo+="文档中锚数量"+anchorNum+"<br/>";
			documentInfo+="文档标题"+document.title+"<br/>";//获取文档标题
			documentInfo+="文档域名"+document.domain+"<br/>";//获取文档域名
			documentInfo+="文档URL"+document.URL+"<br/>";//获取文档URL
			document.getElementById("docInfo").innerHTML=documentInfo;//显示文档内容
			
		}
	</script>
	<body>
		<a href="https://www.baidu.com/" name="baiduAnchor">
			<img src="img/baidu.png" /></a>
		<a href="https://www.so.com/ "name="360Anchor">
			<img src="img/360.png" /></a>
		<a href="https://www.sogou.com/" name="sougouAnchor">
			<img src="img/sougou.png" /></a><br />
			
		<input type="button" value="获取文档信息" onclick="getDocument()"/>
		
		<div id="docInfo"></div>
	</body>
</html>
原文:http://www.cnblogs.com/wxhhts/p/7954862.html