'identify by js when user stops loading page

I need identify, when user going to new page, and if it slowly, identify if the user click in the "stops" browser.

    // remove the timer when the pages finally exits.
    window.addEventListener("unload", function (event) {
        closesWaitingNewPage();
    })

    window.addEventListener("beforeunload", function (event) {
        if (typeof checkChangesBeforeLoad != 'undefined') {
            return checkChangesBeforeLoad(event);
        }
    });

So, i show a loader for my user, waiting load new page. But, if he cancel on browser, my loader still showing.

How can i solve?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source