Submit Your Article Forum Rules

Results 1 to 6 of 6

Thread: search bots and Javascript

  1. #1
    Senior Member
    Join Date
    Feb 2004
    Posts
    263

    search bots and Javascript

    I've read many times that the general concensous is that search bots can't read Javascript. So, I modified some of the code on my site in the hopes that bots would see a direct link while humans who click would go through a click tracking script:

    Code:
     
    <a href="http:/www.otherSite.com" onClick="window.open('http://www.mysite.com/clickTrackingScript.php?bannerID=1234')">
    Text
    </a>
    I'm finding, however, that some bots still open the tracking script. So, is it a myth that bots can't read Javascript, or does that really mean bots can't read text/HTML generated by a Javascript?

    Is there a better way to do what I'm trying do?

  2. #2
    WebProWorld MVP wige's Avatar
    Join Date
    Jun 2006
    Posts
    3,138

    Re: search bots and Javascript

    In my experience, at least the Google Bot is able to follow links in Javascript, despite their claims to the contrary. I ran into issues when Google started crawling pages from a AJAX system I was testing, where the only possible way to find the link was through the javascript. I am not sure how thorough this method is, however. You might be able to scrample the address in a javascript function to prevent the bots from crawling it.
    The best way to learn anything, is to question everything.
    WigeDev - Freelance web and software development

  3. #3
    Senior Member seiretto's Avatar
    Join Date
    Nov 2006
    Posts
    162

    Re: search bots and Javascript

    Quote Originally Posted by pdstein View Post
    Is there a better way to do what I'm trying do?
    Use AJAX. And here is how, add this:
    Code:
    onClick="track_the_click('1234')"
    to the relevant links and add the JavaScript below to each page:
    Code:
    <script language="JavaScript"><!--
    // Free with compliments from Seiretto ;-)
    var url="http://www.mysite.com/clickTrackingScript.php?bannerID=";
    function getHTTPObject()
    {
     if (typeof XMLHttpRequest != 'undefined')
      {
      return new XMLHttpRequest();
      }
      try
      {
      return new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try
      {
       return new ActiveXObject("Microsoft.XMLHTTP");
       } catch (e) {}
       } return false;
    }
    function track_the_click(id)
    {
     var http = getHTTPObject();
     http.onreadystatechange = function()
     {
     if (http.readyState == 4) // 4 is complete
     {
      //alert(http.responseText); // uncomment to see the response!  
     }
     }
     http.open("GET", url+id, true);
     http.send(null);
    }
    // -->
    </script>
    If you do not want any bots following your links in your scripts change the above line
    FROM:
    Code:
    var url="http://www.mysite.com/clickTrackingScript.php?bannerID=";
    TO:
    Code:
    var url1="http://www.mysite";
     url2=".com/clickTrackingScript.php?bannerID=";
    url=url1+url2;
    // most bots are too stupid to put the two together so will not index it (at least currently).
    Hope it helps.

    Dave.
    Experienced UK website host hosting sites for over a decade; Need to host mutliple domains and websites check out our Reseller hosting or try our Fully managed servers

  4. #4
    Senior Member
    Join Date
    Apr 2004
    Posts
    393

    Re: search bots and Javascript

    seiretto's javascript method is a good one to use. I actually came across the exact same problem, my simple solution was to place the tracking script into a seperate directory and disallow that directory in my robots.txt.

    Of course my solution assumes the bots follow the robots.txt rules, which the legit ones do.

  5. #5
    Senior Member
    Join Date
    Feb 2004
    Posts
    263

    Re: search bots and Javascript

    Dave, thanks for the suggestion. I'll give it a try.

    - Paul

  6. #6
    Senior Member
    Join Date
    Jul 2003
    Posts
    398

    Re: search bots and Javascript

    In my understanding, spiders (bots) do not interpret JavaScript per see. Because to be meaningful they'd need to build a DOM and that is way to expensive in terms of computation.

    However, because many webmasters to use JavaScript to actually map links in the navigation, the spiders do a cursory scan for patterns of URL's in scripting. So they find your complete tracking URL, while not finding it when the URL is composed out of two string constants.

    I think imvain2's solution is the best to your problem. And if you want to can also block folks that do not follow the robots.txt rules, using a bit of Redirect magic, involving the referrer URL (which needs to be a page and not blank like most spiders do).

    K<o>

Similar Threads

  1. Attempting to understand search bots/meta tagging
    By astro in forum Search Engine Optimization Forum
    Replies: 3
    Last Post: 04-19-2008, 11:19 PM
  2. Search Bots Eating Bandwidth
    By josephx in forum Internet Security Discussion Forum
    Replies: 29
    Last Post: 01-15-2008, 02:48 PM
  3. Search Bots
    By ohlson in forum Graphics & Design Discussion Forum
    Replies: 1
    Last Post: 09-10-2004, 12:54 PM
  4. Search Bots Behaving Badly
    By Garrett in forum Insider Reports
    Replies: 1
    Last Post: 05-12-2004, 09:16 PM
  5. Search Engine Bots
    By wclew in forum Search Engine Optimization Forum
    Replies: 7
    Last Post: 02-04-2004, 04:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •