Fork me on GitHub

前端实现返回上一层页面

当前的页面的url下标为0,所以window.history.go(-1) 就是要定位到相对页面下表为-1的页面, 也就是之前刚刚访问的页面;
//返回上一页:
window.history.go(-1);

//返回上两个页面:
window.history.go(-2);
window.history.back(-1)和windos.history.go(-1) 都是返回之前的页面 但是方法不同 所以也有所区别:
  window.history.back(-1)//直接返回当前页的上一页,数据全部消失,是个新页面
  window.history.go(-1)//也是返回上一页面,不过表单的数据还在
项目经验实例:  
  <button type="button" class="btn btn-danger" style="position:relative; float:right;bottom:49px;"
onclick="javascript:window.history.go(-1)">返回

总结:  

    <input type=button value=刷新 onclick="window.location.reload()">

    <input type=button value=前进 onclick="window.history.go(1)">

    <input type=button value=后退 onclick="window.history.go(-1)">

    <input type=button value=前进 onclick="window.history.forward()">

    <input type=button value=后退 onclick="window.history.back()"> //后退+刷新








posted @ 2019-01-07 10:26  路痴队长  阅读(6524)  评论(0编辑  收藏  举报