title: Javascript: Whitespace Characters being Removed in Chrome (but not Firefox)
body: <p>Why would the below eliminate the whitespace around matched keyword text when replacing it with an anchor link? Note, this error only occurs in Chrome, and not firefox.</p>
  
  <p>For complete context, the file is located at: <a href="http://seox.org/lbp/lb-core.js" rel="nofollow noreferrer">http://seox.org/lbp/lb-core.js</a></p>
  
  <p>To view the code in action (no errors found yet), the demo page is at <a href="http://seox.org/test.html" rel="nofollow noreferrer">http://seox.org/test.html</a>. Copy/Pasting the first paragraph into a rich text editor (ie: dreamweaver, or gmail with rich text editor turned on) will reveal the problem, with words bunched together. Pasting it into a plain text editor will not.</p>
  
  <pre><code>// Find page text (not in links) -&gt; doxdesk.com
  function findPlainTextExceptInLinks(element, substring, callback) {
      for (var childi= element.childNodes.length; childi--&gt;0;) {
          var child= element.childNodes[childi];
          if (child.nodeType===1) {
              if (child.tagName.toLowerCase()!=='a')
                  findPlainTextExceptInLinks(child, substring, callback);
          } else if (child.nodeType===3) {
              var index= child.data.length;
              while (true) {
                  index= child.data.lastIndexOf(substring, index);
                  if (index===-1 || limit.indexOf(substring.toLowerCase()) !== -1)
                      break;
                  // don't match an alphanumeric char
                  var dontMatch =/\w/;
                  if(child.nodeValue.charAt(index - 1).match(dontMatch) || child.nodeValue.charAt(index+keyword.length).match(dontMatch))
                      break;
                  // alert(child.nodeValue.charAt(index+keyword.length + 1));
                  callback.call(window, child, index)
              }
          }
      }
  }
  
  // Linkup function, call with various type cases (below)
  function linkup(node, index) {
  
      node.splitText(index+keyword.length);
      var a= document.createElement('a');
      a.href= linkUrl;
      a.appendChild(node.splitText(index));
      node.parentNode.insertBefore(a, node.nextSibling);
      limit.push(keyword.toLowerCase()); // Add the keyword to memory
      urlMemory.push(linkUrl); // Add the url to memory
  }
  
  // lower case (already applied)
  findPlainTextExceptInLinks(lbp.vrs.holder, keyword, linkup);
  </code></pre>
  
  <p>Thanks in advance for your help. I'm nearly ready to launch the script, and will gladly comment in kudos to you for your assistance.</p>