location对象
location对象,是window对象的一个属性,代表浏览器上URL地址栏,使用location对象可以操作地址栏
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function fun1(){
console.log(location.host);// 服务器的IP+端口号
console.log(location.hostname);// IP
console.log(location.port);// 端口号
console.log(location.href);// 地址栏中具体的文字
location.href="https://www.baidu.com"
}
</script>
</head>
<body>
<input type="button" value="测试location" onclick="fun1()" />
</body>
</html>
![](https://i-blog.csdnimg.cn/blog_migrate/6de3c20d32c424aadba46c7cc33f1e1a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/434ee72ad5f6167024f27a003dac4d65.png)
history对象
history对象是window对象的一个属性,代表浏览器访问历史记录,通过history的操作我们可以实现翻阅浏览器历史网页
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function fun1(){
window.history.forward();
}
function fun2(){
history.back();
}
function fun3(){
history.go(2); // 正整数 向前跳转 * 页 负整数 向后跳转*页
}
</script>
</head>
<body>
<a href="a.html" target="_self">pageA</a>
<input type="button" value="向前" onclick="fun1()"/>
<input type="button" value="向后" onclick="fun2()"/>
<input type="button" value="go" onclick="fun3()"/>
</body>
</html>
![](https://i-blog.csdnimg.cn/blog_migrate/e770b0442c1318b9d94dfdd848a12c83.png)
![](https://i-blog.csdnimg.cn/blog_migrate/40307fcb81ae2cc72f09cbed0fa75b75.png)
screen和navigator
screen代表屏幕,navigator代表浏览器软件本身,通过这两个对象可以获得屏幕和浏览器软件的一些信息
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function fun1(){
console.info(window.screen.width)
console.info(window.screen.height)
console.info(navigator.userAgent)
console.info(navigator.appName)
}
</script>
</head>
<body onload="fun1()">
</body>
</html>
![](https://i-blog.csdnimg.cn/blog_migrate/5ec13728670df51560bcf1504305095f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7fa99cbe17db85225184379d62eaa3fa.png)