Page Visibility API使用方法自行百度,简单说只要把以下代码加到<head>之间即可逗起来(当浏览器Tab处于非当前页的时候,标题栏会自动换成可爱的大白字符形象)。
<script>
(function() {
‘use strict’;
var RelTitle= document.title;
// Set the name of the “hidden” property and the change event for visibility
var hidden, visibilityChange;
if (typeof document.hidden !== “undefined”) {
hidden = “hidden”;
visibilityChange = “visibilitychange”;
} else if (typeof document.mozHidden !== “undefined”) { // Firefox up to v17
hidden = “mozHidden”;
visibilityChange = “mozvisibilitychange”;
} else if (typeof document.webkitHidden !== “undefined”) { // Chrome up to v32, Android up to v4.4, Blackberry up to v10
hidden = “webkitHidden”;
visibilityChange = “webkitvisibilitychange”;
}function handleVisibilityChange() {
if (document[hidden]) {
document.title = ‘(●––●) Hi,Baby’;
} else {
document.title = ‘<?php wp_title(‘|’, true, ‘right’); ?>’;
}
}// Warn if the browser doesn’t support addEventListener or the Page Visibility API
if (typeof document.addEventListener === “undefined” || typeof document[hidden] === “undefined”) {
alert(“This demo requires a modern browser that supports the Page Visibility API.”);
} else {
// Handle page visibility change
document.addEventListener(visibilityChange, handleVisibilityChange, false);
}})();
</script>
感谢devework.com。
发表评论