Skip to content

Instantly share code, notes, and snippets.

@tylertadej
Created December 2, 2015 22:31
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tylertadej/f4ea1445068507a1b2ea to your computer and use it in GitHub Desktop.
Save tylertadej/f4ea1445068507a1b2ea to your computer and use it in GitHub Desktop.
Change page title when browser tab is unfocused
/*
* 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