Skip to content

Commit 32a305b

Browse files
committed
Script moved to seperate Js file
1 parent bfd7328 commit 32a305b

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,10 @@
7878
</environment>
7979
@*<script type="text/javascript" src="~/js/bundle/header.js"></script>*@
8080
<partial name="~/Views/Shared/_ValidationScriptsPartial.cshtml" />
81+
8182
@RenderSection("Scripts", required: false)
83+
<script type="text/javascript" src="~/js/pageunload.js" asp-append-version="true"></script>
8284
<script type="text/javascript">
83-
// This function will be called when the browser window is closed or unloaded
84-
function tellServerBrowserClosed() {
85-
// Send an asynchronous request to the server when the browser is closed
86-
fetch('/api/user/browser-close', {
87-
method: 'POST',
88-
headers: {
89-
'Content-Type': 'application/json'
90-
},
91-
body: JSON.stringify({ message: 'Browser closed' })
92-
})
93-
.then(response => response.json())
94-
.catch(error => console.error('Error sending data to server:', error));
95-
}
96-
9785
// Bind the function to the unload event
9886
window.onunload = tellServerBrowserClosed;
9987
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
 // This function will be called when the browser window is closed or unloaded
2+
function tellServerBrowserClosed() {
3+
// Send an asynchronous request to the server when the browser is closed
4+
fetch('/api/user/browser-close', {
5+
method: 'POST',
6+
headers: {
7+
'Content-Type': 'application/json'
8+
},
9+
body: JSON.stringify({ message: 'Browser closed' })
10+
})
11+
.then(response => response.json())
12+
.catch(error => console.error('Error sending data to server:', error));
13+
}

LearningHub.Nhs.WebUI/Views/Shared/Tenant/LearningHub/_Layout.cshtml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,9 @@
161161
@RenderSection("Scripts", required: false)
162162

163163
<script type="text/javascript" src="~/js/mkplayer-ui-custom.js" asp-append-version="true"></script>
164+
<script type="text/javascript" src="~/js/pageunload.js" asp-append-version="true"></script>
164165

165166
<script type="text/javascript">
166-
// This function will be called when the browser window is closed or unloaded
167-
function tellServerBrowserClosed() {
168-
// Send an asynchronous request to the server when the browser is closed
169-
fetch('/api/user/browser-close', {
170-
method: 'POST',
171-
headers: {
172-
'Content-Type': 'application/json'
173-
},
174-
body: JSON.stringify({ message: 'Browser closed' })
175-
})
176-
.then(response => response.json())
177-
.catch(error => console.error('Error sending data to server:', error));
178-
}
179-
180167
// Bind the function to the unload event
181168
window.onunload = tellServerBrowserClosed;
182169
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
 // This function will be called when the browser window is closed or unloaded
2+
function tellServerBrowserClosed() {
3+
// Send an asynchronous request to the server when the browser is closed
4+
fetch('/api/user/browser-close', {
5+
method: 'POST',
6+
headers: {
7+
'Content-Type': 'application/json'
8+
},
9+
body: JSON.stringify({ message: 'Browser closed' })
10+
})
11+
.then(response => response.json())
12+
.catch(error => console.error('Error sending data to server:', error));
13+
}

0 commit comments

Comments
 (0)