how to call the onbeforeunload in link click event jquery? -
I have a div tag with a text box and there is a link button outside the div I * Im using the datatable JS and custom column "edit" adding as a link, the href = "#" ..
-
If IM clicks on links without having to enter any data it Meaning the Onbeforeunload function should not be called.
-
Before putting any data into the text box before clicking on Save, click on the im link that means it should call the on-win function. And you have to show messages like saving your changes.
& lt; Div id = "input form" & gt; Details & lt; Input type = "text" id = "description" placeholder = "enter details ..." name = "description" /> & lt; Input type = "submit" value = "save" /> & Lt; / Div & gt; & Lt; A href = 'www.google.co.in' & gt; Link & lt; / A & gt;
$ ('# inputform'). ('Change keyboard keyboard', 'input, text, select', function e) {$ (this) .addClass ('change-input');}); $ (Window) .on ('beforeunload', function () {if ($ ('.convert-input') length) {Return 'you have saved your changes.';}});
Use a variable
saved to track whether the Save button was clicked or not. You can see it in the unlocking event:
var saved = true; $ (Function () {$ ('input [type = submit]'). (Function () {// saving ... saved = true;}); $ ('# inputform'). (' (Key) 'keydown keydown', 'input, textarea, select', function (e) {$ (this) .addClass ('change-input'); saved = false;}); $ (window) .on (' beforeunload ',) function () (if saved!) (if ($ (' .convert-input '). length) {return' you have saved your changes. ';}}}) $ ( Document) .on ('click', 'a [ar]', function () {if (saved!) {If ($ ('.convert-input'). Length) {confirmation of return You ( "You have unsaved changes. ');}}})}}
Comments
Post a Comment