Search code examples
javascriptperformancehttp-redirectpagespeeddevice

How check if pages still not full loading after 12 second, using javascript


I want this code top.location.href= 'http://myweb.com/super-minimal-page.html'; only target devices that take a long time to load my page (maybe more than 12 second still not full loading my page).


Solution

  • document.readyState will return "complete" when the page has finished loading. You can set a timeout and check if the value of readyState isn't "complete" after 12 seconds.

    setTimeout(function () {
        // Not complete. Document hasn't finished loading.
        if (document.readyState !== 'complete') {
            top.location.href = 'http://myweb.com/super-minimal-page.html';
        }
    }, 12000);