问题描述
我正在使用以下js在浏览器/窗口关闭之前显示弹出窗口.但是它似乎没有用.
I'm using the following js to show a popup before the browser/window closes. But it does not seem to be working.
$(window).bind('beforeunload', function(e) {
$('#beforeclose').click();
});
我要显示的弹出窗口是 prettyPopin .而#beforeclose
是锚点的ID,在窗口卸载之前,我试图用它来绑定click事件.我注意到本机js弹出窗口有效,但jQuery弹出窗口不起作用.
The popup i'm trying to show is prettyPopin . And the #beforeclose
is the id of the anchor with which i'm trying to bind the click event before the window unloads. I have noticed that native js popups work but the jQuery popup does not work.
有没有一种方法可以实现我想要的目标?请确实向我解释或引导我进入相应的链接,因为我不是js方面的专家.
Is there a way to achieve what i want to? Please do explain to me or refer me to the respective link because i'm not an expert at js.
提前谢谢.
推荐答案
您不能安全地做到这一点.
You cannot safely do that.
onbeforeunload
旨在避免完全阻止用户离开您的页面.您唯一要做的就是返回一个带有消息的字符串,说明用户为什么不想离开页面.此消息将显示给用户除非他使用的是Firefox .
onbeforeunload
is designed in a way to avoid completely preventing the user from leaving your page. The only thing you should do is return a string with a message why the user might not want to leave the page. This message is displayed to the user unless he's using firefox.
这篇关于在浏览器窗口关闭之前显示jQuery弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!