How to run a "notification" inside javascript.. - Online | Offline Check

I have this simple script on my website to check if its online or not…

I want to show my

<dmx-notifications id="notifies1" align="full" newest-on-top closable position="bottom" offset-x="100"></dmx-notifications>

So I want this alert to appear then the site is offline

notifies1.danger('The network connection has been lost.');

How would i “call” this up in the javascript below?

<script>

        // addEventListener version

window.addEventListener('offline', (event) => {

console.log("The network connection has been lost.");

document.getElementById("connectionstatus").innerHTML = "The network connection has been lost.";

});

// onoffline version

window.onoffline = (event) => {

console.log("The network connection has been lost.");

};

// addEventListener version

window.addEventListener('online', (event) => {

console.log("You are now connected to the network.");

document.getElementById("connectionstatus").innerHTML = "You are now connected to the network.";

});

// ononline version

window.ononline = (event) => {

console.log("You are now connected to the network.");

};

    </script>
Community Page
Last updated: