简体   繁体   English

在refress上显示自定义弹出窗口,并在javascript / jquery中关闭浏览器/选项卡

[英]show custom popup on page refress and browser/tab close in javascript/jquery

I want to open popup when closing the tab or browser first time and get the user review. 我想在第一次关闭标签页或浏览器时打开弹出窗口,并获得用户评论。 I used onbeforeunload() , but I need to handle page refresh and tab close deferent different event. 我使用了onbeforeunload() ,但是我需要处理页面刷新和制表符关闭的其他事件。

Short answer: You can't. 简短的回答:不能。

Longer answer: For rather obvious "security" reasons it is very limited what you can do when a user tries to navigate away from a page / close a tab or in any other way leave the site. 更长的答案:出于非常明显的“安全性”原因,当用户尝试离开页面/关闭选项卡或以任何其他方式离开站点时,您只能执行有限的操作。

The reason is that browsers want to make absolutely sure that you cannot prevent the user from closing a tab or window that he / she wants to close. 原因是浏览器要绝对确保您不能阻止用户关闭他/她想要关闭的选项卡或窗口。

Therefore the onbeforeunload javascript event - and by extension the beforeunload jQuery event - are extremely limited in what they can do. 因此, onbeforeunload javascript事件-并扩展了beforeunload jQuery事件-在其功能上受到极大限制。 One of the things they definitely cannot do is prevent the page from closing - except using one very standardized and rather boring method the browser (usually) allows. 他们绝对不能做的一件事就是阻止页面关闭-除了使用浏览器(通常)允许的一种非常标准化且相当无聊的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM