Created
December 2, 2015 22:31
-
-
Save tylertadej/f4ea1445068507a1b2ea to your computer and use it in GitHub Desktop.
Change page title when browser tab is unfocused
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
/* | |
* Usage | |
* The following code will modify the title of the browser tab on the "blur" event and change it back to the original on the "focus" event. | |
* http://developers.optimizely.com/javascript/code-samples/index.html#advanced-use-cases-browserTab-test | |
*/ | |
// store the original tab title | |
var origTitle = document.title; | |
// function to change title when focusing on tab | |
function oldTitle() { | |
document.title = origTitle; | |
} | |
// function to change title when un-focusing on tab | |
function newTitle() { | |
document.title = 'HELLO WORLD'; | |
} | |
// bind functions to blur and focus events | |
window.onblur = newTitle; | |
window.onfocus = oldTitle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment