admin管理员组文章数量:1291688
I have a few links in my page and I want to call a function when the page is trying to reload.
I tried
$(window).unload(function() {
alert('Handler for .unload() called.');
});
It is not working.
I have a few links in my page and I want to call a function when the page is trying to reload.
I tried
$(window).unload(function() {
alert('Handler for .unload() called.');
});
It is not working.
Share Improve this question edited May 23, 2012 at 6:28 oers 18.7k13 gold badges68 silver badges76 bronze badges asked May 22, 2012 at 10:33 Kanishka PanamaldeniyaKanishka Panamaldeniya 17.6k31 gold badges127 silver badges194 bronze badges 3- "Not working" in what browser? – raina77ow Commented May 22, 2012 at 10:37
- @raina77ow -> google chrome......... – Kanishka Panamaldeniya Commented May 22, 2012 at 10:40
- @KanishkaPanamaldeniya: what actions(s) do you want to perform onunload? Also, bear in mind unload is called: "... when the user navigates away from the page... clicked on a link... typed in a new URL... The forward and back buttons [and] ... closing the browser window [and] ... a page reload will first create an unload event." (Source). – c24w Commented May 23, 2012 at 19:16
3 Answers
Reset to default 4Console: Blocked alert('Handler for .unload() called.') during unload.
(in Chrome)
I assume this is blocked for user-experience reasons.
If you try console.log('Handler for .unload() called.');
the call is made successfully.
Edit: see $(window).unload is not firing
you can try:
window.onbeforeunload = function() {
}
window.onbeforeunload = unloadMessage;
function unloadMessage() {
//do your codeing here...
}
本文标签: javascripthow to call a function before page reload jqueryStack Overflow
版权声明:本文标题:javascript - how to call a function before page reload jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741535631a2384008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论