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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM