在浏览器窗口关闭之前显示jQuery弹出窗口

编程入门 行业动态 更新时间:2024-10-27 05:26:52
本文介绍了在浏览器窗口关闭之前显示jQuery弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下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弹出窗口

本文发布于:2023-10-06 19:44:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出窗口   浏览器   窗口   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!