html 获取地址栏信息

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
   <button onclick="getInfo();">获取信息</button>
    
    <script>
		function getInfo() {
			//获取当前网址,如: http://localhost:8081/index
			var curWwwPath = window.document.location.href;
			//获取主机地址之后的目录,如: idnex
			var pathName = window.document.location.pathname;
			var pos = curWwwPath.indexOf(pathName);
			//获取主机地址,如: http://localhost:8081
			var localhostPaht = curWwwPath.substring(0, pos);
			alert(curWwwPath);
		}
    </script>
</body>
</html>

原文地址:https://www.cnblogs.com/lick468/p/10942096.html