Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $(...).unload is not a function - JQuery 3.1.0

Tags:

jquery

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

like image 229
elG Avatar asked Aug 19 '16 04:08

elG


1 Answers

Try to change like below, because you are using jquery-3

$(window).on("unload", function(e) {     alert("call");     console.log("this will be triggered"); }); 
like image 111
Jekin Kalariya Avatar answered Oct 04 '22 15:10

Jekin Kalariya