/tutorial-navigator-network-connection

๐Ÿ“กCheck with JavaScript the status of the network connection from your web application and show the user a personalized message.

Primary LanguageJavaScriptMIT LicenseMIT

Tutorial JavaScript Navigator Network Connection

๐Ÿ“กCheck with JavaScript the status of the network connection from your web application and show the user a personalized message.



JavaScript The Network Information

๐Ÿ“ How to work with this project

1๏ธโƒฃ Installation

npm i

2๏ธโƒฃ Run

npm run start

3๏ธโƒฃ Usage

Open: http://localhost:3000

๐ŸŽฎ How to include and work with this library in your project?

1๏ธโƒฃ Include the library in your project.

Copy the "check-connection.js" file into your project.

2๏ธโƒฃ Create a new js file, for example "app.js" and add the following lines:

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>

๐Ÿ“‚ Code Scaffolding

/
โ”œโ”€โ”€ assets ๐ŸŒˆ                   # Images Sources.
โ”œโ”€โ”€ src ๐Ÿ“ฆ                      # Express Server Application.
โ”œโ”€โ”€ public ๐Ÿ‘€                   # Front Demo Application.
|   โ”œโ”€โ”€ style                   # Style CSS sources.
|   โ”œโ”€โ”€ js                      # JS file library and example.
|   โ””โ”€โ”€ ...
โ””โ”€โ”€ ...

๐Ÿ“Œ More Info

Mozilla Developers Navigator.onLine
W3C The Network Information API

โ›ฝ๏ธ Review and Update Dependencies

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

License

MIT

Happy Code

Created with JavaScript, lot of โค๏ธ and a few โ˜•๏ธ

This README.md file has been written keeping in mind

GitHub Markdown
Emoji Cheat Sheet