So I am building my website using HTML/CSS. I would like to know what is the easiest way to check if a URL is availble?
For example, I have a table with a cell that shows a link to some URL -
<table class="table table-hover table-bordered table-condensed" cellspacing="0" width="1300" id="ServerTable">
<thead>
<tr>
<th><center> #</center></th>
<th width="100%"><center> Server Name </center></th>
<th><center> Owner </center></th>
<th><center> Project </center></th>
<th width="100%"><center> Description </center></th>
<th width="100%"><center> IP Address </center></th>
<th width="100%"><center> ILO </center></th>
<th><center> Rack </center></th>
<th><center> Status </center></th>
<th><center> Actions </center></th>
</tr>
</thead>
<tbody>
{% for server in posts %}
<tr>
<div class ="server">
<td></td>
<td width="100%"><center>{{ server.ServerName }}</center></td>
<td width="100%"><center>{{ server.Owner }}</center></td>
<td width="100%"><center>{{ server.Project }}</center></td>
<td width="100%"><center>{{ server.Description }}</center></td>
<td width="100%"><center>{{ server.IP }}</center></td>
<td width="100%"><center><a href="//{{ server.ServerName }}.ilo.lab.dba.co.il"> http://{{ server.ServerName }}.ilo.lab.dba.co.il </a></center></td>
<td width="100%"><center>{{ server.Rack }}</center></td>
<td width="100%"><h4><span class="badge badge-success">Online</span></h4></td></center>
In this cell, there is a link to some url. I want to show the link as URL (a href) only if http://{{ server.ServerName }}.ilo.lab.dba.co.il is working using http! (server.ServerName is a variable running in a for loop giving different DNS URLS) If it's not, I will show just a text, or not show it all...
I have found some functions in Javascript that return true and false, but I dont know how to call the function in my html. Like, I was thinking of doing if (link works) : show link with a href, else: show just the string...
Is it possible using Javascript function? If so, what's the function and how do I call it?
An example for a function I found:
How can I use and test it in my code? using href if it's true?
function UrlExists(url)
{
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status==200;
}