I'm trying to execute a function before redirecting to other page, but when the original page loads I get the error that I wrote in the title:
TypeError: $(...).unload is not a function
I've tried this:
$( window ).unload(function() { return "Bye now!"; });
And this:
$(window).unload(function(){ cambiar_ruta(); alert(ruta); });
But nothing is working,I don't even get a Leaving page warning.
With next code I don't get an error, but the function is never triggered and the alert never shown:
var ruta; $(window).bind('onbeforeunload', function(e){ alert('Bye.'); cambiar_ruta(); alert(ruta); });
I'm using jquery-3.1.0.min
Try to change like below, because you are using jquery-3
$(window).on("unload", function(e) { alert("call"); console.log("this will be triggered"); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With