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>
![](/i/l/?n=23&i=blog/2531222/202301/2531222-20230108214010874-296065842.gif)
![点击并拖拽以移动](/i/l/?n=23&i=blog/2531222/202301/2531222-20230108214010874-296065842.gif)
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>
![](/i/l/?n=23&i=blog/2531222/202301/2531222-20230108214010874-296065842.gif)
![点击并拖拽以移动](/i/l/?n=23&i=blog/2531222/202301/2531222-20230108214010874-296065842.gif)
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 onl oad="fun1()">
</body>
</html>
![](/i/l/?n=23&i=blog/2531222/202301/2531222-20230108214010874-296065842.gif)
![点击并拖拽以移动](/i/l/?n=23&i=blog/2531222/202301/2531222-20230108214010874-296065842.gif)
标签:function,console,对象,常见,location,window,6.3,BOM,history From: https://www.cnblogs.com/89564f/p/17035505.html