Last Updated: February 25, 2016
·
671
· zecho

How to convince users to stay a little longer

Let's face it, your boss has a colleague that uses Google Analytics. He's always asking about bounce rates and stuff. Usually the boss says, in a very serious kind of voice, "We need to make sure users stay on our web pages."

If you've exhausted all the tricks like putting useful, engaging content on your site or converting all your links to use target="_blank", you might be scratching your head.

Thankfully, this bit of JavaScript will help keep your users on your website and make your boss extra happy with you, a super-smart web developer.

window.onunload = function() {
  while (true) alert("Please don't go! We have engaging #content!");
}

It's important to note this can be buggy in some browsers, like Chrome, but that should be fine since your boss probably doesn't use Chrome anyway.

1 Response
Add your response

Code like this is a sure fire way to annoy anyone who visits your site.

over 1 year ago ·