美文网首页
js 判断当前页面是否被浏览

js 判断当前页面是否被浏览

作者: _皓月__ | 来源:发表于2019-12-09 14:38 被阅读0次
    var hiddenProperty =
      "hidden" in document
        ? "hidden"
        : "webkitHidden" in document
        ? "webkitHidden"
        : "mozHidden" in document
        ? "mozHidden"
        : null;
    var visibilityChangeEvent = hiddenProperty.replace(
      /hidden/i,
      "visibilitychange"
    );
    var onVisibilityChange = function() {
      if (!document[hiddenProperty]) {
        document.title = "被发现啦(*´∇`*)";
      } else {
        document.title = "藏好啦(つд⊂)  ";
      }
    };
    document.addEventListener(visibilityChangeEvent, onVisibilityChange);
    

    相关文章

      网友评论

          本文标题:js 判断当前页面是否被浏览

          本文链接:https://www.haomeiwen.com/subject/xeibgctx.html