๐กCheck with JavaScript the status of the network connection from your web application and show the user a personalized message.
npm i
npm run start
Open: http://localhost:3000
Copy the "check-connection.js" file into your project.
import checkConnection from './check-connection.js';
window.addEventListener("load", () => {
/**
* This Example show how you can create a new instance of checkConnection class
* for show top banner with #contentMessage id and with a delay for hide in 1000 milliseconds.
*/
const instanceCheckConnection = new checkConnection(
'contentMessage',
'โ
The network connection has been restored',
'๐ซ The network connection has been lost',
1000
);
// Active for show top banner if the connection change.
instanceCheckConnection.active();
/**
* You can desactive this component with the next line:
* instanceCheckConnection.desactive();
*/
});
3๏ธโฃ Add the reference to your js file in your html file, for example "app.js" (it is important to add it as a module):
<script type="module" src="js/app.js"></script>
/
โโโ assets ๐ # Images Sources.
โโโ src ๐ฆ # Express Server Application.
โโโ public ๐ # Front Demo Application.
| โโโ style # Style CSS sources.
| โโโ js # JS file library and example.
| โโโ ...
โโโ ...
Mozilla Developers Navigator.onLine
W3C The Network Information API
To review and update all of this project's npm dependencies you will need to install globally the "npm-check-updates" package.
# Install and Run
$npm i -g npm-check-updates
$ncu
Created with JavaScript, lot of โค๏ธ and a few โ๏ธ