Page history - back button exists?

前端 未结 5 1190
遇见更好的自我
遇见更好的自我 2020-12-09 18:28

Is it possible check if there is a value for history.go(-1)? I know you can\'t access history.previous directly.

I am trying to stay away from document.referrer beca

5条回答
  •  时光取名叫无心
    2020-12-09 19:06

    Actually, history.length is always one or more, since the current page counts. Also, if you have a forward history (i.e. you used the back button), those pages also count. So you need a more complicated check:

    if( (1 < history.length) && document.referrer ) {
    

提交回复
热议问题