Detect if page is load from back button

后端 未结 7 845
无人及你
无人及你 2021-02-06 23:07

Is there any way to detect if current page came from back button?

I want to load data from cookie only if current page came from back button.

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 00:01

    I think this could be done with sessionStorage if you are working with pages within your project(This does not take external pages into account). Off the top of my head, when you are on your "Main Page" then you click a link and go to the next page.

    On that next page, you can set a value in sessionStorage like:

    sessionStorage.setItem('doSomething', 'yes');
    

    Then back to your Main page, you can have a condition like:

    const sCheckSession = sessionStorage.getItem('doSomething');
    if(sCheckSession == 'yes') {
      // do something crazy, then reset your reference to no
      // so it wont interfere with anything else
      sessionStorage.setItem('doSomething', 'no');
    }
    

提交回复
热议问题