Blog

Tutorial: Amazon.com Search API

Posted on

7b. Product Item Description

Product Item Description Code

// Item Description
      var li4 = cel('p');
      li4.style.cssText = "font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #333333; font-weight:normal; margin-top:0px; margin-bottom:2px;";
      if(tmpItem.desc)
      {
         // RegEx used to strip out extraneous HTML and Entities in Description text
         tmpItem.desc = tmpItem.desc.replace(//gi, '');
         tmpItem.desc = tmpItem.desc.replace(/&.*?;/gi, ' ');
         if(tmpItem.desc.length > 121)
         {
            tmpItem.desc = tmpItem.desc.substr(0, 120) + "..."
         }
         li4.appendChild(ctn(tmpItem.desc));
      }

Since the product item description in sometimes written in HTML code, the above code for the product item description includes a javascript replace function to strip out any HTML entities that could compromise the document code. Regular expressions are used to match those characters associated with HTML.