Skip to content

Instantly share code, notes, and snippets.

@rbarros
Created October 9, 2014 13:05
Show Gist options
  • Save rbarros/d758d46847342e4f85c3 to your computer and use it in GitHub Desktop.
Save rbarros/d758d46847342e4f85c3 to your computer and use it in GitHub Desktop.
OnBeforeUnLoad
// include EventListener https://gist.github.com/rbarros/6c7888320ee0cdc3bab7
// include Ajax https://gist.github.com/rbarros/2776240
function OnBeforeUnLoad(e) {
e.preventDefault();
var ajax = Ajax.open({
method: 'GET',
url: 'http://localhost/',
dataType: 'json',
//data: { id: 1 },
success: function (json) {
console.log(json);
}
});
return 'Realmente deseja sair ?';
}
EventListener.addEvent(document.getElementsByTagName('a'), 'click', function () {
OnBeforeUnLoad = function() {};
});
EventListener.addEvent(document.getElementsByTagName('input'), 'submit', function () {
OnBeforeUnLoad = function() {};
});
window.onbeforeunload = OnBeforeUnLoad;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment