Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
Notify script on tab close #1
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-long committed Jun 11, 2020
1 parent 0a10b19 commit 45c50b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ExTRA.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ try {
$context.Response.OutputStream.Write($pageContentUTF8, 0, $pageContentUTF8.Length)
$context.Response.Close()
}
elseif ($context.Request.HttpMethod -eq "PUT") {
Write-Host "Browser tab was closed without saving changes."
break
}
elseif ($context.Request.HttpMethod -eq "POST") {
$reader = New-Object System.IO.StreamReader($context.Request.InputStream, "UTF8")
$body = $reader.ReadToEnd()
Expand Down
6 changes: 6 additions & 0 deletions ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
checkboxesDiv.innerHTML = "";
newChildElements.forEach(c => checkboxesDiv.appendChild(c));
}

window.onbeforeunload = () => {
fetch(window.location.href, {
method: 'PUT'
});
};
</script>

</html>

0 comments on commit 45c50b9

Please sign in to comment.