0

I want to customize the default box to display my own fancybox form to make customer to subscribe for my website.

In the below code, first it's displaying the default dialog box and then my form is displaying. But I want to display my fancybox first. I tried like below. But I can't achieve output what I expected. How can i solve this?

$(document).ready(function () {
    // Shadow box initialization
    Shadowbox.init({
        handleOversize: "resize",
        overlayOpacity: 0.9
    });

    // This makes sure that the pop up isn't shown
    // if the user is navigating within the website
    $(window).click(function () {
        window.onbeforeunload = null;
    });
    window.onbeforeunload = function (e) {
        //console.log(Event);
        //e.preventDefault();
        //e.defaultPrevented();

        //open thickbox
        Shadowbox.open({
            content: '<div id="welcome-msg">Welcome to my website!</div>',
            player: "html",
            width: 540,
            height: 380
        });
        return 'You have unsaved changes!';
    }
});
emerson.marini
  • 9,331
  • 2
  • 29
  • 46
kalyan
  • 171
  • 1
  • 11
  • possible duplicate of [How can I override the OnBeforeUnload dialog and replace it with my own?](http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own) – Stephen P Sep 20 '14 at 07:16
  • there is any alternate jquery plugin with customization Stephen? – kalyan Sep 20 '14 at 07:28

1 Answers1

0

If you simply return the function, it will pop up the default confirm box.

All you have to do is figure out when exactly will you want your 'fancy box' to be replaced by the default confirm box, and then return the message.

So instead of going straight to returning, wait for the user to make an action (subscribe/not subscribe) and then return the message.

Perhaps you could create a global bool and return the message in the beforeunload event only if the bool is true.

If you cannot or don't want to detect when they make an action, you could just place a timer; it's totally up to you.