Last active
February 13, 2018 10:48
-
-
Save tgirardi/5f0944f2fd22452db3dd1dc4c0dfd5c2 to your computer and use it in GitHub Desktop.
Tab title toggle to recover visitors who went to another tab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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