Skip to content

Instantly share code, notes, and snippets.

@tgirardi
Last active February 13, 2018 10:48
Show Gist options
  • Save tgirardi/5f0944f2fd22452db3dd1dc4c0dfd5c2 to your computer and use it in GitHub Desktop.
Save tgirardi/5f0944f2fd22452db3dd1dc4c0dfd5c2 to your computer and use it in GitHub Desktop.
Tab title toggle to recover visitors who went to another tab
<!-- TITLE TOGGLE - paste this just above the </body> tag -->
<script>
(function () {
var t1 = document.title;
var t2 = 'Come BACK! 💘 DON\'T FORGET ME !!'; // <-- CUSTOMIZE THIS
var interval;
window.addEventListener('blur', function () {
interval = window.setInterval(function () {
document.title = document.title === t1 ? t2 : t1;
}, 1000);
});
window.addEventListener('focus', function () {
window.clearTimeout(interval);
document.title = t1;
});
})()
</script>
<!-- END TITLE TOGGLE -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment