Possible duplicate:How to stop page unloading (moving) in JS?Request for unsaved changes when exiting a web page
I have a php form that I created in Dreamweaver containing only text fields that retrieve one record at a time from my database. On this page there is also a button “Update record”, which, when clicked, updates the database record with any changes made to the data in the form. I want that if the user somehow edits the form data and tries to leave the page without clicking the "Refresh record" button, it will be suggested that the page contains unsaved changes, and they will be asked to check whether they want to leave the page or not ( possibly using some javasript if possible).
Any help is greatly appreciated.
onbeforeunload , : , , , .
onbeforeunload
, . , , , .
window.onbeforeunload = function(e) { if (unsavedChanges) return 'Dialog text here.'; };
, . alert confirm onbeforeunload, onunload .
alert
confirm
onunload
"on" api jquery.
var flag = true; // set this var according to your use. $(window).on('beforeunload', function(){ if(flag) { return "It looks like you have input you haven't submitted." } });
Source: https://habr.com/ru/post/1615223/More articles:Elasticsearch HTTP authentication in Spring - javaПочему я получаю предупреждение "Expression always true"? - c#Prevent user from navigating with unsaved changes - javascriptКак перенаправить на другую страницу в angular и Ionic - angularjsПредварительный просмотр камеры является черным при использовании getExternalStorageDirectory для сохранения видео - androidApache Commons Imaging Maven Dependency - javaКак очистить данные из Википедии по категориям? - pythonHow to create a NullObject template using RxJava - androidChecking unsaved changes when switching views in backbone.js - javascriptGIT: error: pathspec 'xxx does not match any file known as git - gitAll Articles