<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="history.go(-1)">history</button>
<!-- 跳转页面 -->
<button onclick="location.assign('https://hao.360.com/')">assign</button>
<!-- 替换页面 -->
<button onclick="location.replace('https://hao.360.com/')">replace</button>
<!-- 跟F5更能一样,重新加载当前页 -->
<button onclick="location.reload()">reload</button>
<script>
console.log(location.href)
console.log(navigator.appName)
console.log(screen.width)
console.log(screen.height)
</script>
</body>
</html>
一、history:用户访问过的站点的列表
属性:length
方法:go()、back()、forward()
只对已经访问过的页面有效
history.go(-3);//向后返回三个访问过的页面
histroy.go(3);//向前返回三个访问过的页面
back();//与history.go(-1);功能相同
forward();//与history.go(1);功能相同
二、location: 载入窗口的URL
属性 | 说明 |
hash | 指定浏览器到一个位于文档中的anchor位置(#之后) |
host | 描述一个url的主机名和端口 |
hostname | url的主机名 |
href | 一个指定对象的整个url字符串 |
pathname | url的路径名部分由于服务器root(根)卷相关的目录结构组成 |
port | 端口号 |
protocol | 包括协议名,后面跟着: |
方法 | 说明 |
assign("url") | 把一个新的url赋值给location对象,页面跳转 |
reload() | 重新加载当前页 |
replace("url") | 通过加载 URL 指定的文档来替换当前文档 |
三、navigator:提供用户使用的浏览器及操作系统等信息
属性 | 说明 |
appCodeName | 浏览器代码名 |
appName | 浏览器名称 |
appVersion | 浏览器版本 |
mimeTypes | MIME类型(navigator.mimeTypes[n].type) |
platform | 浏览器操作系统 |
browserLanguage | 浏览器使用的语言 |
userAgent | 浏览器用户代理(用户浏览器Header头信息) |
四、screen:获取用户屏幕信息
属性 | 说明 |
width | 返回屏幕宽度(像素数) |
height | 返回屏幕高度 |
availWidth | 返回屏幕的可用宽度(除去一些不自动隐藏的类似任务栏的东西所占用的宽度 |
availHeight | 返回屏幕的可用高度 |
colorDepth | 返回当前颜色设置所用的位数,-1:黑白;8:256色;16:增强色;24/32:真彩色 |