DEV Community

Discussion on: Sure you want to leave?—browser beforeunload event

Collapse
 
sashirocks1 profile image
Sashi • Edited

I use the following piece of code in 'beforeunload' to delete a user session during logout, but this fails to clear the user session on a firefox browser, can you please help out here
var req = new XMLHttpRequest();
req.open('DELETE', URI, true);
req.setRequestHeader("TOKEN", $rootScope._TOKEN);
req.send(null);

Collapse
 
samthor profile image
Sam Thorogood

Don't send an XMLHttpRequest—use sendBeacon, like I mentioned in the article.