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>

You can do it all with Wappler rather than using Javascript. Add a Browser and a notify component to the page. Add a dynamic action in the Browser -> Offline dynamic event

Add some text. Done.

1 Like

Thanks you @scalaris… i always overthink these things… or forget they are hidden somewhere … as there is just so much in Wappler… as we take it for granted… so so many functions … and awesomeness… just not always clear where to look… :wink: :slight_smile: thanks … great solution…

Thank you Mozzi. We are all guilty of this behaviour from time to time.