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
Post a Comment