jquery - Showing alert box on `beforeunload` event -


i want show alert box on beforeunload event. using following code that. problem this, not show alert box on event.

$(window).bind('beforeunload', function() {                 alert($(location).attr('hostname'));             }); 

how can problem resolved?

$(window).on('beforeunload', function(){   return location.host; }); 

this have do.

basically can use without jquery

window.onbeforeunload=function(){ return location.hostname; }; 

Comments