-8

Is there a way to get a popunder code when someone closes a site? I've searched on Google, but couldn't find a way or an answer.

Basically: user no longer wants to stay on a particular website, he it's close button ("x" button) and a popunder appears.

  • Have you looked into the `unload` event? Also, don't do this... Unless you are helping people keep local changes to a page, don't be low and serve an ad. – evolutionxbox Apr 16 '16 at 17:32
  • 1
    While this is possible I have two problems with this question. One, your Google search must have been very cursory. Two, this is an annoying thing to do to a user. – HeadCode Apr 16 '16 at 17:34
  • So, have you looked into the unload event? Or used google? Also, what's a *popunder*? – evolutionxbox Apr 16 '16 at 17:35
  • I might not be a good Google searcher, I'm trying to help a person out with this code. – El Patron Apr 16 '16 at 17:36
  • Seriously though. Have you googled the unload JS event? I'm pretty sure that is what you need to get started. – evolutionxbox Apr 16 '16 at 17:39

1 Answers1

-1
            window.onbeforeunload = function(event) {
            var message = 'Important: Please click on \'Save\' button to leave this page.';
            if ( typeof event == 'undefined') {
                event = window.event;
            }
            if (event) {
                event.returnValue = message;
            }
            return message;
        };

        $(function() {
            $("a").not('#lnkLogOut').click(function() {
                window.onbeforeunload = null;
            });
            $(".btn").click(function() {
                window.onbeforeunload = null;
            });
        });
Rajiv
  • 78
  • 10
  • First of all, don't give a jQuery answer when the question doesn't mention that they're using jQuery. Secondly, which part of this creates the popunder? – JJJ Apr 16 '16 at 17:51
  • Thirdly, this seems to have been copy-pasted from http://stackoverflow.com/a/20853978 without attribution. – JJJ Apr 16 '16 at 17:52