How to create an exit traffic script like this?

Discussion in 'HTML & JavaScript' started by Krasavchik, Mar 11, 2015.

  1. Krasavchik

    Krasavchik Newbie

    Joined:
    Nov 23, 2014
    Messages:
    3
    Likes Received:
    0
    Please open the following site and close it to see the effect (and turn on your speakers):

    thrhgwgh .ru/netnuilida

    Does someone maybe know how to create such an exit traffic script with popup, page change and audio?

    Don't worry, it's harmless affiliate site.

    Regards
     
    Last edited: Mar 11, 2015
  2. vayacondios

    vayacondios Newbie

    Joined:
    Mar 3, 2015
    Messages:
    30
    Likes Received:
    5
    I did not go to the site, but here is some code that does a couple of things when the user leaves the page.

    1) embed an audio file in the page with the HTML5 audio tag

    <audio id="mysound" src="/sound.wav" preload="auto"></audio>

    2) Hook into the window unloading event. Originally I just called the play() method on the audio tag, but what I found was I got less than one second played and I was gone. So I added a confirm message box. This prompts the user to click the Leave Page prior to actually going and as such the user hears my full 4 second wav file.

    <script>
    window.onbeforeunload = function(e) {
    var confirmPlease= "listen to this";
    var e = e || window.event;
    if (e) {
    e.returnValue = confirmPlease;
    document.getElementById('mysound').play();
    }

    return confirmPlease;
    }
    </script>
     
  3. seapunk

    seapunk Registered Member

    Joined:
    Dec 28, 2014
    Messages:
    85
    Likes Received:
    20
    Search Google for "exit intent script". You should be able to find code and tutorials to achieve the same thing.