SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If found adsense targeting code

    I am taking the contents of a webpage:

    var body = document.body.innerHTML;

    How can i scan body and if it finds:

    <!-- google_ad_section_start -->
    <!-- google_ad_section_end -->

    the body content becomes just what's within those tags?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just pass the code you want to test, i'm doing that via a textarea at the moment.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Untitled Document</title>
            <link rel="stylesheet" type="text/css" media="screen" />
            <style type="text/css"></style>
            <script type="text/javascript">
                function getContent(what) {
                    var r = new RegExp(/<!-- google_ad_section_start -->([^&#172;]+)<!-- google_ad_section_end -->/g);
                    var m = r.exec(what);
    
                    if(m == null) {
                        alert('unable to get information');
                        return;
                    } else {
                        alert(m[1]);
                    }
                }
            </script>
        </head>
        <body>
            
            <textarea id="test" style="width: 400px; height: 200px;"><!-- google_ad_section_start -->
    <head>
      <title>Your Title Here</title>
    
      <meta name="AUTHOR" content="your name">
      <meta name="DESCRIPTION" content="your description - make sure it's appropriate to your
    article, descriptive enough for Google search to index it correctly, and for appropriate
    AdSense content to be targetted.">
      <meta name="keywords" content="your keywords - ditto the above">
      <meta name="copyright" content="Copyright (c) 2006, your name">
      <meta name="robots" content="index, follow">
      <meta name="revisit-after" content="1 week">
      <meta name="language" content="english">
      <meta name="distribution" content="global">
      <meta name="rating" content="general">
    </head>
    <!-- google_ad_section_end --></textarea>
    <br /><br /><input type="button" value="Get Content" onclick="getContent(document.getElementById('test').value);" />
    
        </body>
    </html>


  3. #3
    SitePoint Wizard
    Join Date
    Mar 2007
    Posts
    1,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code is suppose to make adsense show ads about the keywords in the tags.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @ rcj662 ? not sure what you mean. Refering to the original question, they wanted to get what was between the two comments and technically set the body to that, i've provided the way to get the content, they can do the rest.


  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, this is correct, i need to scan the body text and if i find the adsense targeting code, i want to set a variable to the contents inside! Thanks Gav, i'm testing out your regex now


Bookmarks

Posting Permissions

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