visibilitychange事件可以检查从后台返回事件,然后通过添加div,强制浏览器刷新页面
var divEle = document.createElement("DIV"); divEle.style.position = "absolute"; divEle.style.left = "0px"; divEle.style.top = "0px"; divEle.style.width = "100%"; divEle.style.height = "100%"; divEle.style.zIndex = "9999999"; divEle.style.backgroundColor = "#000"; document.addEventListener("visibilitychange", () => { try { if (document.hidden) { document.body.appendChild(divEle); } else { document.body.removeChild(divEle); } } catch (e) { } });
原文地址:https://www.cnblogs.com/IWings/p/11102088.html
时间: 2024-10-14 15:22:22