Skip to content

Commit a45e237

Browse files
committed
Subscribe to the 'beforeunload' event and trigger the toggleUnsavedChangesModal if the users prevents closing the window
1 parent 2f8d537 commit a45e237

File tree

1 file changed

+12
-0
lines changed
  • src/routes/projects/[projectId]/workflows/[workflowId]

1 file changed

+12
-0
lines changed

src/routes/projects/[projectId]/workflows/[workflowId]/+page.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
datasets = $page.data.datasets;
4747
});
4848
49+
// Add an event listener for the 'beforeunload' event
50+
window.addEventListener('beforeunload', function(e) {
51+
if (argumentsWithUnsavedChanges === true) {
52+
// Cancel the event
53+
e.preventDefault();
54+
// Toggle the modal
55+
toggleUnsavedChangesModal();
56+
// Chrome requires returnValue to be set
57+
e.returnValue = '';
58+
}
59+
});
60+
4961
async function handleExportWorkflow() {
5062
const response = await fetch(`/projects/${project.id}/workflows/${workflow.id}/export`, {
5163
method: 'GET',

0 commit comments

Comments
 (0)