title: removing scripts from html data... using javascript
body: <p>So I have this function to strip out scripts from the page, but some scripts that are many lines long are still showing up.  Is there a way to remove all scripts from the page that loads.</p>
  
  <pre><code> function filterData(data){
  
  // filter all the nasties out
  // no body tags
  data = data.replace(/&lt;?\/body[^&gt;]*&gt;/g,'');
  // no linebreaks
  data = data.replace(/[\r|\n]+/g,'');
  // no comments
  data = data.replace(/&lt;--[\S\s]*?--&gt;/g,'');
  // no noscript blocks
  data = data.replace(/&lt;noscript[^&gt;]*&gt;[\S\s]*?&lt;\/noscript&gt;/g,'');
  // no script blocks
  data = data.replace(/&lt;script[^&gt;]*&gt;[\S\s]*?&lt;\/script&gt;/g,'');
  // no self closing scripts
  data = data.replace(/&lt;script.*\/&gt;/,'');
  
  // [... add as needed ...]
  return data;
    }
  </code></pre>
  
  <p>Here is an example of the script that comes through in the html</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var ccKeywords="keyword=";
  if (typeof(ccauds) != 'undefined')
  {
   for (var cci = 0; cci &lt; ccauds.Profile.Audiences.Audience.length; cci++)
  {
    if (cci &gt; 0) ccKeywords += "&amp;keyword="; ccKeywords +=     ccauds.Profile.Audiences.Audience[cci].abbr;
  }
  }
  &lt;/script&gt;
  </code></pre>