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>

posted @ 2019-05-29 10:15  lick  阅读(1939)  评论(0编辑  收藏  举报