Simple AJAX call to Hide a Form from bots and Search Engines

Tired of the “Spambots” that crawl around the internet and find email adresses and forms to send and submit spam to. This can help hide your forms from bots. This is also a way to hide “affiliate forms” from the likes of Google, Yahoo and MSN. The current trend is to devalue affiliate sites that are there just to send traffic to another site. By inserting your left or right column list of affiliate links or a submission form that sends data to the affiliated company. This will help reduce the detection of such links and forms.

This is really a simplistic approach and if you are really trying to hide a number of links or forms, there should be more validation and care to not display the forms and links to Google bots or Google employees. Renaming the script file and the name of the script to more of a general function name may also help from automated detection.

You need the XHConn.js script to use the code below. Download XHConn here.

Do to the browser caching ajax pages called, I added a random number to the XHConn xmlhttp.open call. This forces a “unique” page call to prevent caching and not displaying updated data. Changes are highlighted.
<!--link XHConn.js in <head> of HTML -->
<script type="text/javascript" src="XHConn.js" ></script>
<!--script can go most anywhere in the HTML code, but is more proper to put in the <head> or top of HTML in the Body -->
<script type="text/javascript" >
window.onload = displayForm
// Requires Javascript and compliant browser on client for Form to be displayed.
function displayForm()
{
// Simple AJAX Form Insert to Hide Form from Spam Bots and Search Engines
var myConn = new XHConn();
if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
var fnWhenDone = function (oXML)
{
document.getElementById("FormHolder").innerHTML = oXML.responseText;
// ID of <div> or other HTML element to hold the form.
};
myConn.connect("/formpage.php", "GET", "" , fnWhenDone);
// formpage.php should hold just HTML to display the form.
return false;
}
</script>

Real Users that don’t have javascript enabled will also not see the form as Javascript is required. If the page you are calling in the AJAX call is .php, .asp, .cfm or other server side scripting language you can take further actions to protect the page from being displayed to the bots or provide an alternate form that does point to your site.

Another option would be having a “fake” form that is in the original pages HTML code and then replace that form with the new one. When looking at the “source code” the user get the originally loaded HTML not the dynamically updated code.

5 comments ↓

#1 Fred on 06.26.08 at 5:10 pm

This didn’t work for me.

.I put the head tag where its supposed to go.
.Created a new file and named it formpage.php and put the form there
.Put the rest of the code where I actually wanted the form to be.
.Downloaded the .js file and put it in the root.
.Uploaded all the files into my root directory

Saved the file as index.php, ran it, just a blank space comes where its supposed to show the form.

#2 JavaScript Junkie on 06.26.08 at 11:23 pm

Can you link to an example page of what you are working on?

#3 Block spiders from PART of a page? - WebProWorld on 08.09.08 at 9:28 am

[...] you want to go for the solution of Kgun (Ajax) I just found this would you might would like to try: Simple AJAX call to Hide a Form from bots and Search Engines — JavaScript Junkie __________________ SEO Workers – Search Engine Optimization Consulting Company | SEO Analysis [...]

#4 Google and Cloaking - WebProWorld on 08.09.08 at 5:02 pm

[...] the page in with the robots.txt file. – Another option would be doing that with Ajax like Simple AJAX call to Hide a Form from bots and Search Engines — JavaScript Junkie – Another option would be You can create a folder called i.e forms and then create a file called [...]

#5 What is Cloaking & Is All Cloaking Evil? on 09.05.08 at 6:08 am

[...] AJAX (here is a post describing a simple method to block a form from bots and search engines with [...]

Leave a Comment