onUnload 이벤트에서 새로고침과 창 닫힘 구분
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function handleUnload()
{
if (self.screenTop > 9000)
{
// 브라우저 닫힘
}
else
{
if (document.readyState == "complete")
{
// 새로고침
}
else if (document.readyState == "loading")
{
// 다른 사이트로 이동
}
}
window.addEventListener('unload', handleUnload);
unload할 때, document.readyState
가 complete면 새로고침으로 판단한다.
This post is licensed under CC BY 4.0 by the author.