javascript - Using onbeforeunload to create a custom confirmation warning? -


i'm trying create custom alert function website. checks if there in form fields, , if there is, should display confirmation message if you're trying navigate away. (excluding submit , cancel button.)

i have code check data, , navigation excluding buttons:

 var leave_page_confirm = true;                          function save_data_check() {                             var msg;                             if (leave_page_confirm === true) {                                 $('.input-right').each(function() {                                     if (this.value) {                                         leave_page_alert();                                     }                                 });                             }                         }  window.onbeforeunload = save_data_check; 

buttons want exclude being seen navigating away page contain:

onclick="leave_page_confirm=false;" 

the leave_page_alert function defined this:

var leave_page_alert = function() {    $("#custom-alert-overlay").show();  } 

without knowing css , html, suffices "custom-alert-overlay" id of element contain buttons.

what i'm stumped on add "leave_page_alert()" in order prevent page loading until 1 of buttons clicked.

for arguments sake, suppose "custom-alert-overlay" contains these buttons:

<button type="button" id="stay">stay on page</button> <button type="button" id="leave">leave page</button> 

despite googling around, haven't managed dig how 1 this...


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -