Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/02/2004, 12:36
kez0
 
Fecha de Ingreso: enero-2004
Mensajes: 431
Antigüedad: 20 años, 3 meses
Puntos: 6
Prueba este:

<HTML>
<TITLE>JavaScript Search Engine Script With Descriptions</TITLE>
<!--This code is originally from Infohiway.com, however, it has been modified-->
<BODY bgcolor=white>
<FORM NAME="database">
<INPUT TYPE="hidden" NAME="list" VALUE='your_first_page.htm~Your First Page Title|keywords For first file go here separated by spaces^First page description here!*http://you.can.use.full.urls.com/you..._page.htm~Your Second Page Title|keywords for second file go here separated by spaces^Second page description here!*your_third_page.htm~Your Third Page Title|keywords for third file go here separated by spaces^Third page description here!*your_fourth_page.htm~Your Fourth Page Title|keywords for fourth file go here separated by spaces^Fourth page description here!*'>
</FORM>
<SCRIPT language="JavaScript">
<!--
function Page(url,title,keywords,description) {
While ((url.length > 0) && (url.charAt(0) == " ")) {
url = url.substring(1,url.length);
}
this.url = url;
While ((title.length > 0) && (title.charAt(0) == " ")) {
title = title.substring(1,title.length);
}
this.title = title;
this.keywords = keywords;
this.description = description;
return this;
}
function Database() {
var pos = 0;
While ((pos1 = amorphous.indexOf("~",pos)) != -1) {
pos2 = amorphous.indexOf("|",pos1+1);
pos3 = amorphous.indexOf("^",pos2+1);
pos4 = amorphous.indexOf("*",pos3+1);
if ((pos2 != -1)
&& (pos2 < pos3) && (pos3 < pos4)
&& (pos4 <= amorphous.indexOf("*",pos))) {
this[database_length++] = new Page(amorphous.substring(pos,pos1),
amorphous.substring(pos1+1,pos2),
amorphous.substring(pos2+1,pos3),
amorphous.substring(pos3+1,pos4));
pos = pos4+1;
} Else { // Error reading amorphous database
if (pos+30 <= amorphous.length)
alert('Error reading in amorphous database around "'
+ amorphous.substring(pos,pos+30) + '"');
pos = amorphous.indexOf("*",pos) + 1;
}
}
return this;
}
function search(str) {
menu_length = 0;
temp = new Object();
temp_length = 0;
words_length = 0;
words = new Object();
pos = 0;
While ((pos = str.indexOf(" ")) != -1
&& and_search != "exact") {
words[words_length] = str.substring(0,pos);
if (words[words_length].length > 0)
words_length++;
if (str.length == 1)
str="";
else
str = str.substring(pos+1,str.length);
}
if (str.length > 0)
words[words_length++] = str;
For (q=0;q<words_length;q++) {
temp_length = 0;
str = words[q].toLowerCase();
len = (and_search=="and"&&q>0?menu_length:database_lengt h);
For (n=0; n<len; n++) {
if (and_search=="and"&&q>0) {
combo = (menu[n].title + " " + menu[n].description
+ " " + menu[n].keywords).toLowerCase();
} Else {
combo = (database[n].title + " " + database[n].description
+ " " + database[n].keywords).toLowerCase();
}
if (combo.indexOf(str) != -1) // found
temp[temp_length++] = (and_search=="and"&&q>0?menu[n]:database[n]);
}
if (and_search!="and" && q>0) {
added = 0;
For (i=0;i<temp_length;i++) {
duplicate = false;
For (j=0;j<MENU_length&&!duplicate;j++) {
if (menu[j] == temp[i]) {
duplicate = true;
}
}
if (!duplicate)
menu[menu_length+(added++)] = temp[i];
}
menu_length += added;
} Else {
for(h=0;h<temp_length;h++)
menu[h] = temp[h];
menu_length = temp_length;
}
}
}
function entry() {
if ((document.entryform.keyword.value.length == 0)
|| (document.entryform.keyword.value == " ")) {
alert("First you must enter a keyword To search for.");
return false;
}
and_search = (document.entryform.and_or.selectedIndex == 0?"and":"or");
if (document.entryform.and_or.selectedIndex == 2)
and_search = "exact";
location.href = location.pathname + "?"
+ escape(document.entryform.keyword.value)
+ (and_search != "or"?"&"+and_search:"");
return false;
}
function redWord(str) {
for(r=0; r<words_length; r++) {
pos = -3;
word = words[r].toLowerCase();
While ((pos = str.toLowerCase().indexOf(word,pos+3)) != -1) {
val = pos+word.length;
str = str.substring(0,pos) + "*"
+ str.substring(pos,val) + "|"
+ str.substring(val,str.length);
}
}
pos = -16;
While ((pos = str.toLowerCase().indexOf("*",pos+16)) != -1)
str = str.substring(0,pos) + "<FONT color=red>"
+ str.substring(pos+1,str.length);
pos = -7;
While ((pos = str.toLowerCase().indexOf("|",pos+7)) != -1)
str = str.substring(0,pos) + "</FONT>"
+ str.substring(pos+1,str.length);
return str;
}
var amorphous = document.database.list.value;
temp_str = amorphous.substring(amorphous.length-2,amorphous.length);
if (temp_str.indexOf("*") == -1)
amorphous += "* ";
else
amorphous += " "; // amorphous database must have characters after last asterisk
database_length = 0; // Netscape 2 fix
var database = new Database(); // read In from amorphous database
menu_length = 0; // Netscape 2 fix
var menu = new Object();
String = "";
and_search = "or";
if (location.search.length > 1) {
String = unescape(location.search.substring(1,location.sear ch.length));
pos = 0;
While ((pos = string.indexOf('"',pos)) != -1) {
String = string.substring(0,pos) + '\\"' + string.substring(pos+1,string.length);
pos += 2;
}
if (string.substring(string.length-4,string.length) == "&and") {
String = string.substring(0,string.length-4);
and_search = "and";
} Else if (string.substring(string.length-6,string.length) == "&exact") {
String = string.substring(0,string.length-6);
and_search = "exact";
} Else if (string.substring(string.length-3,string.length) == "&or") {
String = string.substring(0,string.length-3);
and_search = "or";
}
search(string);
}
document.write('<FORM name="entryform" onSubmit="return entry()">'
+'<B>Search for:</B><BR><INPUT type="text" size=20 '
+'name="keyword" value="'+string+'"> '
+'<INPUT type="button" value="Search" onClick="entry()"><BR><Select name="and_or" '
+'size=1><OPTION'+(and_search=="and"?" selected":"")+'>find all words '
+'(AND)<OPTION'+(and_search=="or"?" selected":"")+'>find any word '
+'(OR)<OPTION'+(and_search=="exact"?" selected":"")+'>exact '
+'match</Select></FORM><BR>');
if (location.search.length > 1)
document.write('<B>Results:</B><BR><BR>\n');
// eliminate the keywords portion of the statement below To eliminate them from your display
For (n=0; n<MENU_length; n++)
document.write('<B><A href="'+menu[n].url+'">'+menu[n].title
+'</A></B><BR>'+redWord(menu[n].description)+'<BR>Keywords: '
+redWord(menu[n].keywords)+'<BR><BR>\n');
if ((menu_length == 0) && (location.search.length > 1))
document.write('Keyword "'+string+'" Not found!\n');
// -->
</SCRIPT>
<HR noshade>
<BR><BR>
The following is just a demonstration of how you would link To search.htm from other pages:<BR><BR>
<!-- if you want To link from another page, just copy the JavaScript code below
and paste it into your other page -->
<SCRIPT language="JavaScript">
<!--
// enter full or relative URL To your search page
var search_htm_url = "your_search_page_name.htm";
function searchPage() {
if ((document.searchpage.keyword.value.length == 0)
|| (document.searchpage.keyword.value == " ")) {
alert("First you must enter a keyword To search for.");
} Else {
sel = document.searchpage.and_or.selectedIndex;
location.href = search_htm_url + "?"
+ escape(document.searchpage.keyword.value)
+ (sel==0?"&and":(sel==2?"&exact":"&or"));
}
return false;
}
document.write('<FORM name="searchpage" onSubmit="return searchPage()">'
+'Search for: <INPUT type="text" size=15 name="keyword"> '
+'<INPUT type="button" value="Search" onClick="searchPage()"><BR>'
+'<Select name="and_or" size=1><OPTION>find all words (AND)<OPTION>find any word '
+'(OR)<OPTION>exact match</Select><BR>"*" wildcards are valid</FORM>');
// -->
</SCRIPT>
<BR><BR>
Or you can just use direct links. For instance, if you wanted To search for the keyword "javascript", Then you would link to <A href="search.htm?javascript">search.htm?javascript </A>. Or search for "javascript" or "perl": <A href="search.htm?javascript%20perl&or">search.htm? javascript%20perl&or</A>. Or for "javascript" and "perl": <A href="search.htm?javascript%20perl&and">search.htm ?javascript%20perl&and</A>. Or for the exact phrase "javascript perl": <A href="search.htm?javascript%20perl&exact">search.h tm?javascript%20perl&exact</A>. (note that %20 is the URL escaped form of a space).
</BODY>
</HTML>
__________________
El que teme preguntar, se averguenza de aprender.