1.location和history
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
/*
* history
* - 该对象代表用户的历史记录,通过它可以对历史记录进行操作
* 由于隐私的原因该对象只能控制浏览器向前或向后翻页
* - 它只可以访问当次(当前会话)的历史记录
*/
window.onload = function(){
//获取按钮对象
var btn01 = document.getElementById("btn01");
//为btn01绑定一个单击响应函数
btn01.onclick = function(){
/*
* length
* - 获取当次访问的历史记录的数量
*/
//alert(history.length);
/*
* back()
* - 可以回退到上一个页面
* - 功能相当于浏览器的后退按钮
*/
//history.back();
/*
* forward()
* - 可以跳转到下一个页面
* - 功能相当于浏览器的前进按钮
*/
//history.forward();
/*
* go()
* - 可以跳转到指定的页面
* - 需要一个整数作为参数,将会跳转指定数量的页面
*/
//history.go(-2);
/*
* location
* - location表示的是浏览器的地址栏的信息
* - 如果直接输出location则会返回当前页面的地址
* - 如果直接修改location的值,则会使浏览器跳转到指定的页面
*
*/
//alert(location);
//location = "test01.html";
/*
* assign()
* - 可以用来跳转到指定的页面
* - 他需要一个路径作为参数,将会跳转到该路径
* - 和直接修改location是一样的
* - 修改location和使用assign()来跳转页面都会生成历史记录
* 可以使用回退按钮回退
*/
//location.assign("test02.html");
//location = "test01.html";
/*
* replace()
* - 使用replace()也可以跳转到其他的页面,同样需要一个地址作为参数
* 用法和assign()一样
* - 不会生成历史记录,不可以回退
*/
//location.replace("test02.html");
/*
* reload()
* - 可以用来刷新当前网页,相当于浏览器的刷新按钮
* - 在该方法中可以传递一个true,如果传了true则会强制清空缓存属性网页
*/
location.reload(true);
};
};
</script>
</head>
<body>
<button id="btn01">点我一下</button>
<input type="text" />
</body>
</html>