Skip to content

Instantly share code, notes, and snippets.

@nagelflorian
Last active August 29, 2015 14:10
Show Gist options
  • Save nagelflorian/9ae14f7bb27b010b1bca to your computer and use it in GitHub Desktop.
Save nagelflorian/9ae14f7bb27b010b1bca to your computer and use it in GitHub Desktop.
Dynamic website title based on user focus, e.g. when a user switches to another browser tab.
<!DOCTYPE html>
<HTML>
<head>
<title>Original Title</title>
<script>
var originalTitle = document.title;
var altTitle = 'Alternative Title';
var onBlurEvents = window.onblur;
var onFocusEvents = window.onfocus;
window.onblur = function() {
document.title = altTitle;
if(onBlurEvents) {
onBlurEvents();
}
}
window.onfocus = function() {
document.title = originalTitle;
if(onFocusEvents) {
onFocusEvents();
}
}
</script>
</head>
</HTML>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment