JavaScript位置对象Location

JavaScript Location对象

JavaScript位置对象Location是窗口对象的一部分,其包含有关当前访问URL的信息。
主机名,端口号,路径名等信息等信息

语法

location.hash

JavaScript位置对象Location示例

<html>
<head>
  <script type="text/javascript">

	  function myfun() {
		  console.log(location.hostname);
	  }

  </script>
</head>
<body>
  <button onclick="myfun()">点击我</button>
</body>
</html>

示例2

JavaScript查看当前URL的端口号

<html>
<head>

  <script type="text/javascript">
	  function myfun() {
		  console.log("端口:-" + location.port);
	  }

  </script>
</head>
<body>
  <button onclick="myfun()">点击我</button>
</body>
</html>
日期:2020-04-18 01:09:28 来源:oir作者:oir