080_获取当前页面地址

1. window.location对象可用于获取当前页面地址(URL)并把浏览器重定向到新页面。

2. window.location.href属性返回当前页面的URL。

3. window.location.hostname属性返回(当前页面的)因特网主机的名称。

4. window.location.pathname属性返回当前页面的路径名。

5. window.location.protocol属性返回页面的web协议(http:或https:)。

6. window.location.port属性返回(当前页面的)互联网主机端口的编号。

7. 例子

7.1. 新建一个Web项目

7.2. 编写Location.html

<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8" />
		<title>获取当前页面地址</title>
	</head>
	<body>
		<script type="text/javascript">
			document.write('页面位置是: ' + window.location.href + '<br />');
			document.write('页面主机名是: ' + window.location.hostname + '<br />');
			document.write('页面路径是: ' + window.location.pathname + '<br />');
			document.write('页面协议是: ' + window.location.protocol + '<br />');
			document.write('端口号是: ' + window.location.port + '<br />');
		</script>
	</body>
</html>

7.3. 效果图

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值