简体   繁体   中英

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");

    }
    }  

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

Connection Manager

Event handler

WebOS services

You can get a connection status by using the webOsDev.js library of WebOS.

webOSDev.connection.getStatus({
    onSuccess: function (res) {
        if (res.isInternetConnectionAvailable === false) {
            //when the internet connection is not available 
        } else {
            //when internet is available
        }
    },
    onFailure: function (res) {
        //on failure to request the API
    },
    subscribe: true
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM