javascript - off() not working in firefox but working in chrome -


i using beforeonload function want when user submits form beforeunload shouldn't work. here code, works fine in chrome not in firefox.

window.form_submitted = '';   jquery(document).ready(function() {     jquery(window).on('beforeunload', function() {         if (form_submitted == '') {             return "are sure leave page";         }     }); });  jquery('#form').on('submit', function (e) {     e.preventdefault();     jquery(window).off('beforeunload');     form_submitted = 1;     site_redirect(resp.payment_url); }   return false; }); 

you have several syntax issues, , have place submit block inside domready handler, otherwise js attempt bind event element doesn't yet exist in dom. note can remove the global flag variable unbinding beforeunload event on form submission. try this:

jquery(document).ready(function($) {     $(window).on('beforeunload', function() {         return "are sure leave page";     });      $('#form').on('submit', function (e) {         e.preventdefault();         $(window).off('beforeunload');         site_redirect(resp.payment_url);     });  }); 

also note doing redirect when form submit (assuming that's site_redirect function doing) content of form lost.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -