Jump to content

Verifying Links With Javascript - Noob Time :d


RecoJohnson

Recommended Posts

Can someone guide me in the right direction?I am trying to verify links and if they are real links they turn green, else they turn red.

<html><head><title>TRYING TO LEARN - NOT WORKING - FUUUUU</title><script type="text/javascript">function isUrl(s) {var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/return regexp.test(s); for(var i=0;i<document.getElementByTagName("a").length;i++){if (isUrl(document.getElementByTagName("a").href)){document.getElementByTagName("a").setAttribute("color","green");}else{document.getElementByTagName("a").setAttribute("color","red");}  }</script></head><body><a href="http://www.google.ca">GOOGLE</a><a href="http://www.9as0danotwaebsite.ca">GOOGLE</a></body></html>

Link to comment
Share on other sites

What do you mean by a "real link"? Your code seems to be checking whether the URL is well-formed or not (though I can't tell whether the regular expression is correct), but http://www.9as0danotwaebsite.ca is perfectly well-formed too (just that no one seems to have registered it yet). If you want to check whether there is a web server at the given domain, or that it returns 200 for the given URL, you will need to co-opt your server using AJAX.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...