Skip to content

Instantly share code, notes, and snippets.

@coelhoadler
Created March 19, 2018 15:37
Show Gist options
  • Select an option

  • Save coelhoadler/85349d42d490ac2840393e370327cf0a to your computer and use it in GitHub Desktop.

Select an option

Save coelhoadler/85349d42d490ac2840393e370327cf0a to your computer and use it in GitHub Desktop.
Testing the visibility API. Every time when I change the browser tab, the title page is changed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>🌍</title>
</head>
<body>
<script type="text/javascript">
document.addEventListener('visibilitychange', (event) => {
if (document.visibilityState === 'hidden') {
document.title = '😴';
}
if (document.visibilityState === 'visible') {
document.title = '😊';
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment