Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:05:52+00:00 2026-05-27T10:05:52+00:00

I need to check if a website is online and to get ping time.

  • 0

I need to check if a website is online and to get ping time.

I already have a rough ping time (close enough). But I still need to check if the site is online and make the function run five times, and get the lowest ping value (in order to get it more accurate).

My code so far:

<script>
  function initPingTest(siteUrl){
    pingTester();
    function pingTester(){
      document.getElementById('site').innerHTML = '<center>' + siteUrl + '</center>';
      document.getElementById('pingT').innerHTML = '<center> testing.. </center>';
    var startTime=new Date();
    window.startTime=startTime.getTime();
    var imgSrc=siteUrl+ '?cacheBuster='+Math.random();
    var iFrame=document.getElementById('myPingTest');
    iFrame.onload=pingTime;
    iFrame.src=imgSrc;
    function pingTime() {
      var endTime=new Date();
      var pingResult = (endTime.getTime()-window.startTime);
      if(pingResult<hidden.hidden.value){
        document.getElementById('pingT').innerHTML = '<center>' + pingResult + '</center>';
        hidden.hidden.value=pingResult;
      }else{document.getElementById('pingT').innerHTML = '<center>' + hidden.hidden.value + '</center>';}
      } 
    } 
  }
</script>

<IFRAME style="display:none;" id=myPingTest></IFRAME>
<FORM NAME="hidden" STYLE="display:none"><INPUT TYPE="text" NAME="hidden" value="100000"></form>
<br>
<FORM method="get" NAME="ping" action="javascript:initPingTest(ping.url.value);"><font>Enter site adress(ie.www.yahoo.com)<br>http://</font>
  <INPUT TYPE="text" NAME="url" size="18"><input type="submit" value="Ping"/></form>
  <br>
  <table cellspacing=5px>
    <tr><th>
      Url:
    </th><th>
      Ping Time (miliseconds)
    </th></tr>
    <tr><td>
      <label id=site><center> - </center></label>
    </td><td>
      <label id=pingT><center> - </center></lable>
    </td></tr>
  </table>
</body></html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:05:52+00:00Added an answer on May 27, 2026 at 10:05 am

    While I don’t believe Javascript ‘really’ offers this kind of functionality, you could create an xmlhttprequest object, and perhaps compare the difference from the time it sends with the time it connects.

    The following code shows a possible way to achieve this:
    Edit: should alert if the server is down now

    var address = "http://www.google.com";
    
    var t1 = Date.now();
    var t2;
    
    var max = 100000;
    var failed = false;
    
    var httpReq = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
    if(httpReq == null) {
        console.log("Error: XMLHttpRequest failed to initiate.");
    }
    httpReq.onreadystatechange = function() {
    
        var failTimer = setTimeout(function() {
                                   failed = true;
                                   httpReq.abort();
                                   }, max);
    
        if (httpReq.readyState == 4) {  //Completed loading
            if (!failed && (httpReq.status == 200 || httpReq.status == 0)) {
    
                clearTimeout(failTimer);
    
                t2 = Date.now();
    
                var timeTotal = (t2 - t1);
                if(timeTotal > max) {
                    onFail();
                } else {
                    onSuccess(timeTotal);
                }
    
            }
            else {  //Otherwise, there was a problem while loading
                console.log("Error " + httpReq.status + " has occurred.");
                onFail();
            }
        }
    }
    try {
        httpReq.open("GET", address, true);
        httpReq.send(null);
    
    } catch(e) {
        console.log("Error retrieving data httpReq. Some browsers only accept cross-domain request with HTTP.");
        onFail();
    }
    
    
    function onSuccess(timeTotal) {
    
        alert("Time needed to connect: " + timeTotal);
    }
    function onFail() {
        alert("Well this isn't good");
    }
    

    An iframe may be a viable solution as well though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check if visitor is first time on website and show block
In a my website I need to customize check boxes with labels. What are
We have a website (foo.com) that does online training. A user logs in, then
I have a website and i need to implement border radius for text box
I am working on a wordpress website where I need to get the number
I have a build a website where users need to login to, and the
I am building a website now for a library and i need to check
i have a high traffic website (1+ Millions visitors per day) and i need
Basically i need to check to see if a website on another domain is
I have a server which is online right now, but requires authentication when accessing,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.