且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何知道窗口是否“加载"事件已经被触发

更新时间:2023-12-04 22:29:22

浏览器 导航性能 loadEventEnd 指标可用于确定是否触发了加载事件:

Browser navigation performance loadEventEnd metric can be used to determinate if load event was triggered:

let navData = window.performance.getEntriesByType("navigation");
if (navData.length > 0 && navData[0].loadEventEnd > 0)
{
    console.log('Document is loaded');
} else {
    console.log('Document is not loaded');
}