How to check if there is an internet connection in Javascript? I have searched in Google but I have not found a good solution for my problem.

I have already got two eventhandler:

document.body.addEventListener("offline", function () {
    //alert("offline")
    masterViewModel.online(false)
}, false);
document.body.addEventListener("online", function () {
    //alert("online")
    masterViewModel.online(true);
}, false);

But how to check in the "onload"-function if I am online?

Edit
Report