Eshan Sudharaka
Eshan Sudharaka

Reputation: 607

Creating a browser Exit popup

What I want to do is detecting the browser close event (on browser unload) and open up a new pop up where we have some options like (give a feedback, go to the page again , mail me a report etc). At the same time I want the parent window alive till the user select an option in pop up window. I tried following and it seems not working.

$(window).bind('beforeunload', function(event){
        event.preventDefault();
    });

Please give me the right direction for achieving this.

Upvotes: 1

Views: 2683

Answers (2)

Brigand
Brigand

Reputation: 86240

You can do this, but users won't see it in Chrome unless they disable the pop-up blocker.

$(window).on("beforeunload", function(){
    window.open("survey.html");
    return "Are you sure you want to leave?";
});

Upvotes: 0

borbulon
borbulon

Reputation: 1411

you can only do it with an alert/dialog

$(window).bind('beforeunload', function(event){
    return "hold on a minute there, conme back and answer some questions";
});

Upvotes: 2

Related Questions