[英]Show custom pop-up on back/forward button press of browsers
I have a special requirement. 我有特殊要求。 I have a web page and when user press back button of the browser on the page, it should show a pop –up message. 我有一个网页,当用户按下页面上浏览器的后退按钮时,它应该显示一个弹出消息。 I tried the codes below but it is not working 我尝试了下面的代码,但它无法正常工作
window.onbeforeunload = function (evt) {
$.fancybox({
content: "<b>some text</B>",
padding: 0,
centerOnScroll: true,
overlayColor: "#000",
overlayOpacity: .7
});
};
This pop up is shown for a moment and taken to the back page itself. 此弹出窗口会显示片刻并转到后页本身。 My intension is to show a custom pop-up with 2 buttons and on clicking 我的目的是显示一个带有2个按钮并单击的自定义弹出窗口
on one of the button it should NOT GO the back page and clicking on the other should go to the back page 在其中一个按钮上它不应该转到后页并点击另一个应该转到后页
is it possible to show such custom pop ups with custom actions? 是否可以显示自定义操作的自定义弹出窗口?
This is simple answer: you cannot! 这是一个简单的答案:你不能!
window.onbeforeunload
only can return string
! window.onbeforeunload
只能返回string
! BTW firefox doesn't allow customized message. BTW firefox不允许自定义消息。
window.onbeforeunload = function (evt) {
return "My message which make users not so happy!";
}
If you want some kind of hacky workaround to make your users never come back to your site, you could see that: 如果您想要某种hacky解决方法让您的用户永远不会回到您的网站,您可以看到:
https://stackoverflow.com/a/16824414/1414562 https://stackoverflow.com/a/16824414/1414562
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.