javascript - process a page on UnLoad? -


i need php file process when user click link/go back/exits page. part of saving user info process. if jquery unload how fire php file load , process.

jquery(window).bind("unload", function() { // should add? });

$(document).ready(function() {        $(':input',document.myform).bind("change", function() {         setconfirmunload(true);      }); // prevent accidental navigation away });  function setconfirmunload(on) {      // avoid ie7 , prior jquery version issues         // directly using window.onbeforeunload event      window.onbeforeunload = (on) ? unloadmessage : null; }  function unloadmessage() {      if(confirm('you have entered new data on page.  if navigate away page without first saving data, changes lost.')) {              $.ajax({                type: "post",                url: "some.php",                data: "name=john&location=boston",                success: function(msg){                  alert( "data saved: " + msg );                }              });      }  } 

make sure have upgraded version of jquery. jquery version 1.3.2 had bug:

ticket #4418: beforeunload doenst work correctly

or use native function:

window.onbeforeunload = function() {....} 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -