Sad Trumbone When Someone Leaves Your Website

Ladies and Gentlemen, I give you: Sad Trumbone When Someone Leaves Your Website

http://jsbin.com/OMEKObA/1/

This cutting edge HTML5 Audio technique can be easily achieved. Simply add an audio element to your page.

<audio id="sad" src="http://soundfxnow.com/soundfx/Sad-Trombone.mp3"></audio>

Then bind the onbeforeunload event and call the play() method on the audio element before returning the prompt message.

//Bind window unload event
window.onbeforeunload = function() {
  //Play sad trumbone
  document.getElementById('sad').play();
  //Return prompt message
  return "Are you sure want to leave? I mean, I am a pretty great site.";
};

About Banzor

Chris Bannon is a Corny Dad. He is a Certified Internet Webmaster and a purveyor of Fine Scripts. Chris is a Both-end Developer from JS to C#. And a Grinder for the Pittsburgh Pharaohs hockey team. View all posts by Banzor →

Comments are closed.