Skip to content

Instantly share code, notes, and snippets.

@oampo
Created November 27, 2018 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oampo/61c1dbb3010f593fe35ba96b42d63cb3 to your computer and use it in GitHub Desktop.
Save oampo/61c1dbb3010f593fe35ba96b42d63cb3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
function onUnload() {
$.ajax({
type: "POST",
url: "http://localhost:8080/unload",
async: false
});
}
window.onbeforeunload = onUnload;
</script>
</body>
</html>
const express = require('express');
const app = express();
app.post('/unload', (req, res) => {
console.log('Unload');
res.json('Wohoo');
});
app.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment