I have been trying to create a javascript to detect on and offline event when a user login to their account, but am currently challenge on how to get offline event to work, since my event icon shows green even when the user is offline, in my case what is the best way to go about this ? is this issue from my script ? or html or css ?here is my script
<script>
window.addEventListener('load', function() {
var user_status = document.getElementById("user_status");
var log = document.getElementById("log");
function updateOnlineStatus(event) {
var condition = navigator.onLine ? "status_online" : "offline";
user_status.className = condition;
user_status.innerHTML = condition.toUpperCase();
log.insertAdjacentHTML("beforeend", "Event: " + event.type + "; Status: " + condition);
}
window.addEventListener('status_online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
});
</script>
my css status icon styling
/* ---------------------------------- */
/* user status icon
------------------------------------- */
.user_status {
position: absolute;
content: "";
height: 14px;
width: 14px;
background-color: #c0c0c0;
bottom: 0;
right: 0;
display: block;
border: 2.5px solid #fff;
border-radius: 50%;
visibility: hidden;
}
.user_status.status_online {
background-color: #38b653;
visibility: visible;
}
Here is my html to display status icon
<div class="profiles_content">
<div class="relative uk-transition-toggle overflow-hidden">
<div uk-form-custom class="w-full py-5" >
<div class="profile_avatar">
<div class="profile_avatar_holder">
<img src="{{ profile_image }}" alt="">
</div>
<div class="user_status status_online"></div>