Check if page gets reloaded or refreshed in JavaScript

前端 未结 12 2865
遇见更好的自我
遇见更好的自我 2020-11-21 22:57

I want to check when someone tries to refresh a page.

For example, when I open a page nothing happens but when I refresh the page it should display an alert.

12条回答
  •  [愿得一人]
    2020-11-21 23:26

    if(sessionStorage.reload) { 
       sessionStorage.reload = true;
       // optionnal
       setTimeout( () => { sessionStorage.setItem('reload', false) }, 2000);
    } else {
       sessionStorage.setItem('reload', false);
    }
    
    
    

提交回复
热议问题