The difference between history.back(-1) and history.go(-1)

1 Overview

H5页面做多了,自然就会做到页面上的返回功能,返回功能大致有两种:history.back(-1)和history.go(-1),今天我们来说说两种方法的区别。 

write picture description here

2. The purpose of this method

There are many ways to return a page, just like binding a URL to the return button, but if a page can be reached from many pages, then the page returned by this page is not fixed, so it is obviously inappropriate to bind a fixed URL.

3. The difference between the two methods

既然history.back(-1)和history.go(-1)都是返回之前页面,但是方法不同,所以肯定是有区别的: 
history.back(-1)//直接返回当前页的上一页,数据全部消息,是个新页面
history.go(-1)//也是返回当前页的上一页,不过表单里的数据全部还在

4. Summary

返回、前进页面的方法下面总结一下: 
window.location.reload() //刷新
window.history.go(1) //前进
window.history.go(-1) //后退
window.history.forward() //前进
window.history.back() 后退+刷新

Blog source address: http://www.uw3c.com/jsviews/js96.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325892610&siteId=291194637