在浏览器选项卡上显示弹出窗口,关闭或离开页面 [英] Show pop up on browser tab close or leave the page
问题描述
我在项目中编写了一个弹出代码.很简单,鼠标移动时我正在使用淡入淡出效果. Bootstrap modal
在mousemove
上显示完美,但是当用户关闭浏览器选项卡或离开页面时,我需要显示模式.以下是我的代码
I have a pop up code written in my project. Simple I was using fading effect when mousemove. Bootstrap modal
was showing perfectly on mousemove
but I need to show modal when user closes the browser tab or leave the page. Below is my code
之前
$(document).on("mousemove", function (e) {
$('#exitpopup').css('top', (window.innerHeight / 2 - $('#exitpopup').height() / 2));
if (abc) {
if (e.pageY >= 5) {
abc = false;
// Show the exit popup
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
abc = 0;
}
}
});
上面的代码工作正常,但是如何在下面的代码中使用fadeIn
或以其他任何方式建议我.
Above code is working fine but how could I use fadeIn
in below code or suggest me any other way please.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
推荐答案
您不能.出于安全原因,在任何浏览器中取消卸载事件的唯一方法是询问.当然,您不能修改浏览器将显示的对话框.您只能提供将在对话框中显示的字符串.而且由于该功能是为了安全起见,所以我认为它们不会以任何方式允许您这样做.
You can't. For security reasons, the only way to cancel the unload event in any browser is to ask. and of course, you cannot modify the dialog box that the browser will show. you can only give a string that will be displayed in the dialog. And since that functionality is for security, i don't think they will allow you to do that in any way.
这篇关于在浏览器选项卡上显示弹出窗口,关闭或离开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!