Hi, I need a JavaScript function tha does that: * Verify if there is an URL in document * If there is so ok. * If not shows an alert. Can anyone help me?
If you mean within the current document something like this: <script type="text/javascript"> window.onload = function() { if(document.body.innerHTML.search("http://www.yahoo.com") == -1) window.alert("URL Could not be found in document."); } </script> Code (markup): You have to make sure that the script is inserted BEFORE the <body> tag of the document....
Hi Camjohnson95, I tried adding code before <body> and it worked perfectly. But there is any way to work inside <body> tag? Regards and thank you very much, Diego
ok, The reason that it needs to be before the body tag is because otherwise it picks up the string from the script and always return true... so if we join two parts of the url to make one it will work fine from anywhere: <script type="text/javascript"> var strUrl; window.onload = function() { strUrl = "http://".concat("www.yahoo.com"); if(document.body.innerHTML.search(strUrl) == -1) window.alert("URL Could not be found in document."); } </script> Code (markup):