Page visibility API

PHP
// function to change the tab title
function changeTabTitle(title) {
  document.title = title;
}

// store the original title
var originalTitle = document.title;

// check if the page visibility api is supported by the browser
if (document.visibilityState !== undefined) {

  // add an event listener to detect a window visibility change
  document.addEventListener('visibilitychange', function() {
    if (document.visibilityState === 'hidden') {

      // when the tab is hidden, change the title to the following
      changeTabTitle('Hey, komm zurück! 😜');
    } else {

      // show the original tab title if the user is back
      changeTabTitle(originalTitle);
    }
  });
}