Hi, I have simple javascript to search static pages in a website
Code:
var item = new Array();
/* Enter the information of your static pages in item array as each entry
following are the 2 sample entries I have made.
The entries should contain
item[c] = new Array("Page Name","path","Page Title","Many,Key,Words","Descriptive Comments")
*/
c=0; item[c]=new Array("index.htm","","info - Everything you ever wanted to know about Sikkim","homepage","info, Everything you ever wanted to know about Sikkim.");
c++; item[c]=new Array("maps.htm","","Maps","content,main,focus","maps of Sikkim.");
page="<html><head><title>Search Results</title><link href='somecss.css' rel=stylesheet type=text/css></head><body bgcolor='white'><span style='background-color: #000000'><p><b><center><font color='#FFFFFF' face='Tahoma' size='2'> Search Result </center></b></p></font></span><center><font face='verdana' size='2'><table border=0 cellspacing=10 width=80%>";
/* search is the function to search contents in website */
function search(frm)
{
if(frm.srchval.value=="" )
alert("please enter the search word");
else
{
win = window.open("","","width=400,height=340,left=200,top=80,scrollbars");
win.document.write(page);
txt = frm.srchval.value.split(" ");
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++)
{
fnd[i] = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if ((item[i][order[j]].indexOf(txt[k]) > -1 || item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 || item[i][order[j]].toUpperCase().indexOf(txt[k]) > -1) && txt[k] != "")
fnd[i] += (j+1);
}
for (i = 0; i < fnd.length; i++)
{
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, win, n);
fnd[w ] = 0;
}
win.document.write("</table><b><hr>Total found:</b> "+total+"<br></font></body></html>");
win.document.close();
}
}
function show(which,wind,num)
{
link = item[which][0] ;
line = "<tr><td><a href='" + link + "' target= '_blank' >" + "<b>" + item[which][2] + "</b></a> " +"<br>" ;
line += "<font face='verdana' size='1'>" +item[which][3] + "</font><br>"+"</td></tr>";
wind.document.write(line);
return 1;
}
I think it helps