javascript - How to warn a user when leaving a page but not when pressing a button? -
i want users warning when leaving webpage. want users different alert when press on button submitting something. @ moment when leave webpage works correctly when press submit see both warning messages. how show 1 alert?
<asp:button style="display: inline-block; margin-left: 120px; margin-top: 10px;" id="sendemail" runat="server" cssclass="btn-flat success" text="send email" onclick="btnupdate_click" visible="true" enabled="true" onsubmit="window.onbeforeunload = false;" onclientclick="if ( !confirm('are sure want send email?')) return false;"/> <script> window.onbeforeunload = function () { return "do want leave page?"; }
i use window.onbeforeunload leaving webpage , have onclientclick called when press on button submitting. have no experience javascript not sure doing.
you can set variable while clicking on submit. when it's true not show window.onbeforeunload
message.
do somthing this.
<asp:button style="display: inline-block; margin-left: 120px; margin-top: 10px;" id="sendemail" runat="server" cssclass="btn-flat success" text="send email" onclick="btnupdate_click" visible="true" enabled="true" onsubmit="window.onbeforeunload = false;" onclientclick="return confirm();" />
and js
var issubmit = false; function confirm() { issubmit = true; if ( !confirm('are sure want send email?')) return false; } if(issubmit != true) { window.onbeforeunload = function () { return "do want leave page?"; } }
thanks
Comments
Post a Comment