document.onactivate = function(){
console.log("index.php is visible");};
有什么帮助吗?
人到中年有点甜
浏览 73回答 2
2回答
慕的地8271018
使用条件检查可见document.addEventListener("visibilitychange", function handleVisibilityChange() { if (!document.hidden) { console.log("index.php is visible"); }}, false);
您可以检查visibilityState文档的。该事件将在页面被激活和停用时触发,但是,这允许您仅在页面被激活时运行代码,即:可见。document.addEventListener("visibilitychange", function() { if (document.visibilityState === "visible") { // code when page is visible console.log("index.php is visible"); }});