FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Become a Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
div
 

JavaScript Tutorial: Keyword Density Analyzer using JavaScript

by: jawahar, 4/14/2008 5:14:47 AM, Views: 221
 
Keyword Density Analyzer is a tool that can be used to find the total number of keywords in a particular piece of text. Creating web pages with a good keyword density(between 4% to 8%) helps in achieving a good search engine ranking.

Just Copy and Paste the below code in a text editor and save it with any filename with extenstion .html and execute it in the browser.

<html>
<head>
<title>JavaScript Keyword Density Analyzer</title>
<script language="JavaScript">
function count(txt_element)
{
   str=document.getElementById(txt_element).innerHTML;
   var words = str.replace(/[^a-zA-Z0-9]/g,' ').split(' ');
   var assoc = new Array();
   total_words=words.length;
   for (i=0; i<total_words; i++)
   {
      if (!words[i])
         continue;
      if (assoc[words[i]] == null)
         assoc[words[i]]=0;
      assoc[words[i]]++;
   }
   output = new Array();
   for (word in assoc)
   {
      output[output.length]=word + ": " + assoc[word] + ", Density: " + Math.round((assoc[word]/total_words)*100) + "%";
   }
   output.sort();
   document.getElementById('outputId').innerHTML="<b>Keyword Density</b><br/><i>Total Words:"+total_words+"</i><br/>"+output.join('<br/>');
}
</script>
</head>
<body>
<h2>JavaScript Keyword Density Analyzer</h2>
<textarea name="txt_text" id="txt_text" cols="50" rows="5"></textarea><br/><br/>
<input type="submit" name="Submit" value="Calculate Keyword Density" onClick="javascript: count('txt_text');">
<br/><br/>
<div id="outputId"></div>
</body>
</html>
Next Steps:
Add this Tutorial to:
Rating Booth
Not Yet Rated!
Rate:
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
     
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
arrow
sep
Get Rid of Spyware with Anti Spyware Software
Options
»  Submit a Tutorial
» Ask a Question
» Add to KB
» View all your Q's
JavaScript RSS Feed
Most Popular Tutorial
1.InStr in JavaScript
2.Mid() function in Ja...
3.Capturing Mouse Posi...
4.Setting IFRAME heigh...
5.Dynamically create/a...
6.Creating floating me...
7.View Clipboard conte...
8.Validating a text bo...
9.Dynamically changing...
10.Javascript Input Box...
Most Popular Solution
1.How to reload a fram...
Top Rated
1.InStr in JavaScript
2.Mid() function in Ja...
3.Dynamically create/a...
4.Opening a New window...
5.Capturing Mouse Posi...
6.Creating floating me...
7.Dynamically changing...
8.View Clipboard conte...
9.How to reload a fram...
Top Rankers
Overall
sep
1. jawahar1400
sep

Yearly - 2008
sep
1. jawahar200
sep
Expertsforge Sponsors
1. Tech News
2. Wii Reviews
bnrtop