0

I tried it with beforeunload of window event.But it shows navigation conformation box.I want to show custom dialog box with textarea to take feedback when closing website. My code is here,

    $(function() {
    $(window).bind('beforeunload',function(){
    document.write('<textarea ></textarea>');
    return false;
    });

Please help me to find it with pleasure.

user3278227
  • 41
  • 1
  • 1
  • 6
  • 1
    There is a very good reason you can't do this. It's extremely annoying. If your users trust you enough to create an account on your website or give you their email and permission to contact them, then use that to ask them asynchronously. – Touffy Feb 23 '15 at 13:51

2 Answers2

0

I believe this is about your only option:

$(window).on('beforeunload', function(){
    return 'Dont Leave';
});

It appears custom dialogs are not possible when leaving a page. After a little digging I was able to find some other posts to explain. Check this one out, the selected answer explains it in-depth: Dialog box runs for 1 sec and disappears?

Community
  • 1
  • 1
wrxsti
  • 3,434
  • 1
  • 18
  • 30
0

You can't, you can only return the text you want to be displayed, for example:

$(function() {
$(window).bind('beforeunload',function(){
     return "Are you sure?";
 });