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
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
! BTW firefox doesn't allow customized message.
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.