012_JS中BOM对象location,history,Navigato,screen学习

ocation,history,Navigato,screen对象

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			/******location的属性********/
			function testLocation(){
				// 返回当前网页的url:http://127.0.0.1:8020/jS_learn/012_JS%E4%B8%ADBOM%E5%AF%B9%E8%B1%A11.html?__hbt=1591887366460
				var herf = window.location.href;
				//返回当前网页的服务器ip:127.0.0.1
				var hostname = window.location.hostname
				// 返回服务器主机:127.0.0.1:8020
				var host = window.location.host;
				//  返回服务器端口:8020
				var port = window.location.port
				//alert(herf+'----'+hostname+'----'+port+'---'+host)
				// 重置herf,跳转到重置后的页面
				window.location.href='http://www.baidu.com'
				// 重新加载页面,刷新
				//window.location.reload()
			}
			
			/*******history对象******/
			function testHistory(){
				// 当前历史记录的个数属性,返回浏览器列表中url的个数
				var lenth = window.history.length
				//alert(length)
				// 前进方法
				//window.history.forward()
				//后退方法
				//window.history.back()
				// 控制前进 或着后退 多个网页,负数代表后退,正数代表前进,为0则刷新当前页面
				window.history.go(1)
			}
			/*******screen对象*******/
			function testScreen(){
				//获取屏幕的高度
				var he =window.screen.height
				// 获得屏幕的宽度
				var wi = window.screen.width
				alert(he+'+++'+wi)
			}
			/***********navigator*********/
			function testNavigator(){
				//获得用户代理
				var user = window.navigator.userAgent
				alert(user)
			}
		</script>
	</head>
	<body>
		<p>
			<input type="button" name="" id="" value="location对象"  onclick="testLocation()" />
		</p>
		<p>
			<input type="button" name="" id="" value="history对象"  onclick="testHistory()" />
		</p>
		<p>
			<input type="button" name="" id="" value="screen对象"  onclick="testScreen()" />
		</p>
				<p>
			<input type="button" name="" id="" value="Navigator对象"  onclick="testNavigator()" />
		</p>
	</body>
</html>
 <!--location  history  nav 等对象的学习是从属性和方法两方门面来学习-->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值