I was reading jQuery documentation for the function .unload()
given in the jQuery API Documentation
It is written clearly that .unload()
will is deprecated in versions after 1.8 and removed pletely in 3.x.
I have a local intranet application that is dependent upon this .unload()
function.
Do I have to manually rely on window.onbeforeunload
function and see that a particular browser supports this or not, or can anyone help me in finding a more generic solution for the same.
As suggested by Kevin, I tried
$(window).on("unload", function(e){
return confirm("Do you really want to exit");
});
<script src=".2.1.min.js"></script>
Testing JQuery Unload in 3.x Version
I was reading jQuery documentation for the function .unload()
given in the jQuery API Documentation
It is written clearly that .unload()
will is deprecated in versions after 1.8 and removed pletely in 3.x.
I have a local intranet application that is dependent upon this .unload()
function.
Do I have to manually rely on window.onbeforeunload
function and see that a particular browser supports this or not, or can anyone help me in finding a more generic solution for the same.
As suggested by Kevin, I tried
$(window).on("unload", function(e){
return confirm("Do you really want to exit");
});
<script src="https://code.jquery./jquery-3.2.1.min.js"></script>
Testing JQuery Unload in 3.x Version
Fiddle
But it is not working
Share Improve this question edited Sep 28, 2017 at 23:54 Makyen♦ 33.4k12 gold badges92 silver badges125 bronze badges asked Sep 27, 2017 at 8:31 vibs2006vibs2006 6,5584 gold badges41 silver badges43 bronze badges 4-
3
replace
.unload()
with.on('unload', function())
which is not deprecated. – Kevin Kloet Commented Sep 27, 2017 at 8:34 -
2
It is written clearly that unload function will not be depreciated in future versions after 1.8 because it is already deprecated in 1.8 there are nothing left to deprecate after 1.8. Use the
on
method , which is the jQuery alternative ofadddEventListener
as suggested by Kevin – Sagar V Commented Sep 27, 2017 at 8:35 - @KevinKloet as per you I have used .on method now. Can u help me in finding out that why my fiddle is not working jsfiddle/vibs2006/bqge8x22 – vibs2006 Commented Sep 27, 2017 at 8:53
- @SagarV my same ment (previous to this ment) question to you too. Pl guide. – vibs2006 Commented Sep 27, 2017 at 8:54
1 Answer
Reset to default 5unload
is a shorthand method in jQuery and is deprecated. When using on
, you have to use the exact same event as present in JavaScript removing on
.
Here, use beforeunload
instead of unload
//$(window).on("unload", function(e){
// ^^^
$(window).on("beforeunload", function(e) {
// ^^^
return confirm("Do you really want to exit");
});
<script src="https://code.jquery./jquery-3.2.1.min.js"></script>
Testing JQuery Unload in 3.x Version
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744195245a4562624.html
评论列表(0条)