I've hidden it

November 12, 2015 · Sharing

titlehide

The magical scene I saw in Sonic 853, a racing boat, decisively splashing water

**Original author: **Kuriyama Mirai who is unhappy all day long

What the hell: Change the title when leaving and entering the page

Principle:

Using HTML5’s Page Visibility API

Currently, the page visibility API has two properties and one event, as follows:

document.hidden: Boolean value, indicating whether the current page is visible or invisible

document.visibilityState: Returns the visibility state of the current page, the values are hidden visible prerender preview

visibilitychange: event triggered when visibility status changes

In the past, I only knew that page visibility could be detected through iframe + onblur/onfocus events. With this API, it is really convenient and elegant.

Code:

var OriginTitile = document.title;
var titleTime;
document.addEventListener("visibilitychange", function () {
  if (document.hidden) {
    document.title = "(つェ⊂)我藏好了哦~ " + OriginTitile;
    clearTimeout(titleTime);
  } else {
    document.title = "(*´∇`*) 被你发现啦~ " + OriginTitile;
    titleTime = setTimeout(function () {
      document.title = OriginTitile;
    }, 2000);
  }
});
DIYgod Hi, DIYgod

Running for 4344 days

© 2026 DIYgod. All rights reserved. Please credit when sharing.