I am trying to display a loading modal when the user goes to another page of my site.
Since more than half of the pages are forms, I decided to display the pop-up by default if the user does not save his data. Here is the javascript code :
$("input, textarea, select").bind('change', function() {
$("button[type='submit']").click(function() {
window.onbeforeunload = function() {
return
}
})
window.onbeforeunload = function(evt) {
var message = '?'
var e = evt || window.event
e.returnValue = message
return message
}
})
$(document).ready(function() {
$('form.modal-trigger').submit(function() {
$('#submit-modal').show()
})
window.onbeforeunload = function() {
$('#submit-modal').show()
}
})
When the user clicks Cancel, all is well, but when he selects OK my modal is not displayed.
Is there any way to display it after the user selects OK ?