简体   繁体   English

在浏览器的后退/前进按钮上显示自定义弹出窗口

[英]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.

相关问题 单击弹出窗口上的自定义按钮后,在地图上显示图钉 - Show pin on the map after clicking the custom button on the pop-up PHP-2个浏览器PHP上的Submit按钮和Modal Pop-up AJAX - PHP - Submit button and Modal Pop-up AJAX on 2 browsers PHP 是否有可能通过CSS或JavaScript在Android浏览器中隐藏“长按”(又称“长按”)弹出对话框 - Is it possible to suppress the “Long Hold” (aka “long press”) pop-up dialog on Android browsers via CSS or JavaScript 无法立即在弹出窗口中“按下”刚刚创建的按钮。 我必须关闭弹出窗口,然后再次打开它(chrome-extension弹出窗口) - Cannot 'press' a just created button inside a pop-up window immediately. I have to close the pop-up and then open it again (chrome-extension pop-up) 如何在 JSP 中单击按钮时显示弹出窗口 - How to show pop-up on button click in JSP 单击一个按钮并显示弹出窗口,而无需使用Alert() - Click a button and show pop-up window without using Alert() HTML 按钮不显示弹出窗口 - HTML button doesn't show pop-up 使用JS显示/隐藏弹出窗口,窗体 - Show/Hide Pop-Up with JS, form 单击以在弹出框中显示图像 - onclick to show an image in pop-up box Fancybox不在弹出窗口中显示图像 - Fancybox does not show image in pop-up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM