javascriptwindowinternet-connectionweboslg

How window.addEventListener('online') Works?


I am just confused Like how this window.addEventListener('online') or window.addEventListener('offline') works. I have created An LGTV WebOS application where I have added that if any video is playing and on during play the video if internet connection is lost it should show an alert message. So I used these window events but they only work when my wifi or network is disconnected not when I have connected to wifi but there is no internet on that. So what I want is alert should be displayed when I have connected to wifi but there is no internet available on wifi is there any way to do this?

window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
function updateOnlineStatus(event) {
    console.log("-----------------Control comes into updateOnlineStatus --------------");
    console.log("event",event);
    var errorModal = document.getElementById("errorModal");
    var condition = navigator.onLine ? "online" : "offline";
    if(condition == "online"){
        console.log("-----------INternet Is conected ----------------");
        errorModal.style.display="none";
        video.play();
    }else{
        console.log("-----------INternet Is NOOOOOOTT conected ----------------");
        video.pause();
        errorModal.style.display="block";
        SpatialNavigation.makeFocusable();
        SpatialNavigation.focus("#ok_btn");

    }
    }  

Solution

  • If you are developing a WebOS TV application, you should check first the native APIs of that platform...

    Connection Manager

    Event handler

    WebOS services