Skip to content

Instantly share code, notes, and snippets.

@seanwalsh
Created July 25, 2014 13:12
Show Gist options
  • Save seanwalsh/7d4201eed50d9da53b62 to your computer and use it in GitHub Desktop.
Save seanwalsh/7d4201eed50d9da53b62 to your computer and use it in GitHub Desktop.
A little bit of Javascript to change the title of a page after loosing focus. For example, switching to another window or tab.
// Change Title Tag on Blur
var titleCurrent = document.title;
var titleList = [
"Hey, over here.",
"Don't you forget about me",
"Please come back"
];
var titleIndex = "";
function titleRandom(){
var index = Math.floor(Math.random() * titleList.length);
titleIndex = titleList[index];
document.title = titleIndex;
}
window.onblur = function () { titleRandom(); };
window.onfocus = function () { document.title = titleCurrent; };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment