0

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?

karthikr
  • 97,368
  • 26
  • 197
  • 188
Kuttan Sujith
  • 7,889
  • 18
  • 64
  • 95
  • here's some info on the onbeforeunload event http://msdn.microsoft.com/en-us/library/ms536907%28VS.85%29.aspx – John Boker Jun 05 '13 at 16:55

1 Answers1

2

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:

https://stackoverflow.com/a/16824414/1414562

Community
  • 1
  • 1
A. Wolff
  • 74,033
  • 9
  • 94
  • 155