Identifying Between Refresh And Close Browser Actions

前端 未结 13 1210
孤街浪徒
孤街浪徒 2020-11-22 15:29

When we refresh the page (F5, or icon in browser), it will first trigger ONUNLOAD event. When we close the browser (X on right top icon),It will trigger ONUNLOAD event. Now

13条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 15:47

    I just tried this and it solved the issue: Create a sessionStorage object which will get destroyed when the user closes the browser. We can check the sessionStorage object to find if the user has closed the browser or refreshed the page(sessionStorage object will not be destroyed on page refresh).

提交回复
热议问题