window.onbeforeunload handling ok and cancel options
问题 I have a window.onbeforeunload function which generates the default message "Are you sure you want to navigate away from this page...." . If we click on "OK" we are redirected to a new link and if we press "cancel" we are redirected back to the same page. I want to save some data from the page when we press "ok" and move away from the page. How can we know if "ok" or "cancel" has been pressed , then make an event call and continue with the "ok"/"cancel" option. 回答1: function leavePage() { /