Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off define which events can actually take your user away from your site?</p> <ol> <li>A click of a link inside your web site content</li> <li>A submit of a form to an outside action</li> <li>A javascript from a child window that changes window.location on its parent</li> <li>User starting a search in the search bar (FF and IE)</li> <li>User entering a search/address in the browser address bar.</li> <li>User hitting a back button (or backspace) when it just came to your site</li> <li>User hitting a forward button (or shift-backspace) when they were off the site before but came back by getting there via Back button functionality</li> <li>User closes the browser window</li> </ol> <p>So. what can you do about all these?</p> <ol> <li>These are easy. Check your anchors and if they do point outside, add some functionality in the <code>onclick</code> event</li> <li>Similar to 1. Add your functionality for the <code>onsubmit</code> event of the form posting back outside of your site.</li> <li>-> 8. don't really have an applicable solution that could be controlled. You can abuse <code>onbeforeunload</code> event as much as you want, but you won't have much success of knowing what's going on. And there are certain limitations related to <code>onbeforeunload</code> as well, so your hands will be tied most of the time.</li> </ol> <h2>The real question?</h2> <p>Why would you want to control this event anyway except for bothering your users not to leave you. Begging doesn't give much justice in the web world anyway. And when some site would bother me with messages or even worse <strong>prevent me</strong> from leaving I wouldn't want to get back anymore. It smells of bad bad bad usability and gives a hint of adware site.</p> <p>Rather <strong>try to keep your users interested</strong> by providing them with valuable content.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload