I googled it before, but I could not find any solution about detecting only window closing event instead of tab closing and refresh events in JavaScript.
I used this code below which works for all cases: closing window, closing tab and also refresh page:
window.addEventListener("beforeunload", function (e) {
..
}
I could not find a solution to differentiate between the different cases, because my need is that I want only to detect window close not tab neither refresh.