I use:

Tuesday, April 08, 2008

Wait don't leave! Resisting user navigation.

When looking for a really nasty bit of trickery I found this article that allows you to manage a user's navigation from the current page to prevent pre-mature departures. I suspect this can be used for good or evil, but it's cool nonetheless.

How to stop browser from closing using Javascript? - Dev Articles

Derived from that article is the simplified version we will use:

<script>
var needToConfirm = false;
window.onbeforeunload = confirmExit;
function confirmExit()
{
//alert(needToConfirm);
if (needToConfirm)
{
window.open("http://cstech.no-ip.com");
//return "[Unremark this line to show the customized confirm dialog with OK/Cancel options.]";
}
}
needToConfirm = true;
</script>
Currently this fires a new window with my site but with the prevelance of pop-up blockers don't expect this to be terribly effective.

No comments: