admin管理员组文章数量:1399022
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
本文标签: javascriptWhat is a foolproof alternative to (window)unload()Stack Overflow
版权声明:本文标题:javascript - What is a foolproof alternative to $(window).unload()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744195244a2594708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论