魏长东

weichangdong

东邪

监测是否离开页面

<script>
var hidden, state, visibilityChange; 
if (typeof document.hidden !== "undefined") {
	hidden = "hidden";
	visibilityChange = "visibilitychange";
	state = "visibilityState";
} else if (typeof document.mozHidden !== "undefined") {
	hidden = "mozHidden";
	visibilityChange = "mozvisibilitychange";
	state = "mozVisibilityState";
} else if (typeof document.msHidden !== "undefined") {
	hidden = "msHidden";
	visibilityChange = "msvisibilitychange";
	state = "msVisibilityState";
} else if (typeof document.webkitHidden !== "undefined") {
	hidden = "webkitHidden";
	visibilityChange = "webkitvisibilitychange";
	state = "webkitVisibilityState";
}

// 添加监听器,在title里显示状态变化
document.addEventListener(visibilityChange, function() {
	//document.title = document[state];
	if (document[state] == 'visible'){
		document.title = 'weichangdong'
	} else {
		document.title = 'look at me'
	}
}, false);

// 初始化
//document.title = document[state];
document.title = 'weichangdong';
</script>