Last active
August 29, 2015 14:10
-
-
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.
This file contains 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
<!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