Online Ping In Vanilla JavaScript – Ping.js

Category: Javascript | August 19, 2020
Author:alfg
Views Total:73 views
Official Page:Go to website
Last Update:August 19, 2020
License:MIT

Preview:

Online Ping In Vanilla JavaScript – Ping.js

Description:

Ping.js is a vanilla JavaScript library to provide an online ping functionality on the client-side.

How to use it:

1. Install & download the package.

# NPM
$ npm i ping.js --save

2. Import the Ping.js as an ES module.

import Ping from 'ping.js';

3. Or load the compiled JavaScript from the dist folder.

<script src="dist/ping.min.js"></script>

4. Create a new Ping instance.

var p = new Ping();

5. Ping a specific website and get the response time.

p.ping("https://cssscript.com", function(err, data) {
  if (err) {
    console.log("no response")
  }
  document.getElementById("output").innerHTML = data;
});

6. Available options to customize the Ping tool.

var p = new Ping({

    // replace it with your own favicon
    favicon: "/favicon.ico",

    // timeout in ms
    timeout: 0,

    // whether to log errors
    logError: false

});

You Might Be Interested In:


Leave a Reply