Skip to content

Commit e51bf7a

Browse files
committed
Add javascript confirmation to prevent close of window #5
1 parent 4beb921 commit e51bf7a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

flask_fastspring.py

+5
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ def milliseconds_to_datetime(m):
245245
<script type="text/javascript">
246246
var fscSession = {{ session|tojson }};
247247
{% if webhook %}
248+
window.onbeforeunload = confirmExit;
249+
function confirmExit() {
250+
return "You have attempted to leave this page. Are you sure?";
251+
}
248252
function fastspringOnPopupClosed(data) {
249253
if (!data) return;
250254
var xhr = new XMLHttpRequest();
@@ -253,6 +257,7 @@ def milliseconds_to_datetime(m):
253257
xhr.onreadystatechange = function() {
254258
if (xhr.readyState === XMLHttpRequest.DONE) {
255259
if (xhr.status === 200) {
260+
window.onbeforeunload = function() {};
256261
window.location.replace("{{ request.url }}");
257262
} else if (xhr.status === 201 || (301 <= xhr.status && xhr.status <= 303)) {
258263
window.location.replace(xhr.getResponseHeader("Location"));

0 commit comments

Comments
 (0)