LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » Check Server/Website Is Online Or Offline Via Pure JavaScript

Check Server/Website Is Online Or Offline Via Pure JavaScript

Check-Server-Website-Is-Online-Or-Offline-Via-Pure-JavaScript
If you want to check any website or server that is it online or not then there are many codes available on internet but 90%+ are using PHP that many hosting doesn’t support. Now if you want to check your desired website is online or offline on without PHP hosting then you have to use JavaScript.

Now if you are thinking that How a JavaScript code can check that any server or website is online or not then the answer is simple that JavaScript hot any image in targeted server or website then if that image response then it will show that it is online or else its offline.

Yes it has drawback like if that image is deleted or change path then it will show Offline but you can update the code with new path. We suggest you to use FAVICON of targeted server or image if you are checking any other server or website because that will not be deleted or changes or if you are check your own server or website then upload a light weight 1Px Transparent GIF(1 × 1 pixels, file size: 42 Byte, MIME type: image/gif) image and use there URL.

Table of Contents

Features:

1.) Pure JavaScript Code.
2.) Easy To Use And Run.
3.) Fully Customizable.
4.) Quick To Run And Check.
5.) Will Check If Server Or Website Is On Or Not.
6.) Hit An Image In Targeted Server Or Website.
7.) Short And Cross Browser Code.
8.) No JQuery Or Any External File…
9.) Online And Offline Warning.
10.) Fast Responce.

How To Use This Code?

You just have to add the below Javascript codw from where you want to check your desired server or website that either its online or not.

<script type='text/javascript'>
 // Check Server/Website Is Online Or Offline Via Pure JavaScript
 // Shared On www.exeideas.com
 var url = 'URL-OF-ANY-IMAGE-IN-SERVER';
 var img = new Image();
 img.src = url;
 img.onload = function()
 {
 alert('SERVER/WEBSITE IS UP AND RUNNING')
 }
 img.onerror = function()
 {
 alert('SERVER/WEBSITE IS DOWN AND NOT-RUNNING')
 }
 </script>

Customization:

1.) Just change URL-OF-ANY-IMAGE-IN-SERVER with any light weight image of your targeted server or website image.
2.) Can change what to show if Online or what to show if Offline.
3.) Save and done.

Last Words:

This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share more codes that will make your coding more easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.

Recommended For You:
How To Disable Right Click Menu In Blog And Website?

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *