Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Stoffo/ead4ec8e51b23882c8d9 to your computer and use it in GitHub Desktop.
Save Stoffo/ead4ec8e51b23882c8d9 to your computer and use it in GitHub Desktop.
var defaultTitle = document.title;
// subscribe to visibility change events
document.addEventListener('visibilitychange', function () {
// fires when user switches tabs, apps, goes to homescreen, etc.
if (document.visibilityState === 'hidden') {
document.title = 'Baby, Come Back!'
}
// fires when app transitions from prerender, user returns to the app / tab.
if (document.visibilityState === 'visible') {
document.title = defaultTitle;
}
});
@Stoffo
Copy link
Author

Stoffo commented Nov 25, 2015

Taken from igvita.com.

To provide a reliable and consistent user experience, both on desktop and mobile, the application must use Page Visibility API and execute its session save and restore logic whenever visibilityChange state changes. This is the only event your application can count on. (Source)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment