用户返回浏览器中打开的此页面时,显示id="model-vote"块中内容:
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]) {
$('#model-vote').attr("style","display:block");
}
if
(document[hiddenProperty]) {
console.log(
'用户离开当前页面时,执行此方法'
);
}
}
document.addEventListener(visibilityChangeEvent, onVisibilityChange);