How to find whether the user clicks browser back button or Refresh button

前端 未结 8 1486
感动是毒
感动是毒 2021-02-07 12:59

I need to find whether the user clicking the browser back button or Refresh button.

I need to redirect the page to Error page when he clicks the back or refresh button.

8条回答
  •  Happy的楠姐
    2021-02-07 13:44

    This simply detects if the user lands on your page using the back/forward buttons... the only problem is with IE8 and lower, the browser version cannot handle this.

    if(performance.navigation.type == 2)
    {
        //Do your code here
    }
    

提交回复
热议问题