clear session when page unloads code example Example: clear session storage on refresh window.onunload = function () { sessionStorage.removeItem('key'); }