Showing posts with label broken links;javascript;jquery. Show all posts
Showing posts with label broken links;javascript;jquery. Show all posts

Tuesday, March 24, 2015

Javascript to check broken links

Hi Guys, recently i came across to find out whether the given set of URL's are broken links or not.

I have created below sample snippet to findout whether a URL exists Or not.

<html>
<head>
<script type = 'text/javascript'>
function IsUrlExists(url) {
  var http = new XMLHttpRequest();
  alert(http);
  http.open('HEAD', url, false);
  http.send();
  alert(http.status);
  return http.status != 404
}
</script>
</head>
<body>
<input type="text" name="Url" id="url">
<input type="button" value="Check" id="btncheck" onclick="IsUrlExists(document.getElementById('url').value);">
</body>
</html>

Hope this helps..

Popular Posts