Foros del Web » Programando para Internet » Javascript »

Buscapalabras sabrias hacer esto? [Buscador interno super sencillo][offline]

Estas en el tema de Buscapalabras sabrias hacer esto? [Buscador interno super sencillo][offline] en el foro de Javascript en Foros del Web. Hola! teniendo la base este formulario que encontré por aqui. Quiero que el mismo cuadro de busqueda me busque en la misma pagina donde esté ...
  #1 (permalink)  
Antiguo 23/11/2009, 15:23
 
Fecha de Ingreso: abril-2009
Mensajes: 51
Antigüedad: 15 años, 1 mes
Puntos: 0
Buscapalabras sabrias hacer esto? [Buscador interno super sencillo][offline]

Hola!

teniendo la base este formulario que encontré por aqui. Quiero que el mismo cuadro de busqueda me busque en la misma pagina donde esté el formulario..

Quiero decir... si la página tiene 6000 palabras quiero que desde un formulario (caja de busqueda) arriba al principio, al poner una de esas palabras baje hasta encontrarla en la misma pagina (como si fueran marcadores)

Alguna idea?? por que no tengo ni una pista!!!

GRACIAS!!!

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!---aqui comienza el buscador -->
<script language="JavaScript">
<!-- Begin
var item = new Array();

// "Nombre de la página","Situación página","Título","Palabras clave","Comentarios descriptivos"

/* links below were changed so a 404 error would not be found if someone actually clicked them in the www.js-examples.com database */
c=0; item[c]=new Array("http://www.imperiomusica.com/hilaryduff.php","","hilary","duff","hilaryduff","H ILARY DUFF", "HILARY", "DUFF","Hilary Duff");
c++; item[c]=new Array("http://www.topmusik.ya.st/","","topmusik","musik,top,mu","Topmusik");


codigo="<h1>Search Results</h1><table border=0 cellspacing=10 width=80%>";

function search(frm) {
win = document.getElementById("resultado");
win.innerHTML=codigo;
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]].toLowerCase().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.innerHTML+="</table><center><br><font size=2>Tu busqueda se ha encontrado:"+total+"<br></body></html></font>";
win.innerHTML+="<hr></table><center><br><b><font size=4><big>ImperioMusica.com<br></font><font size=2></head></html></font>";
win.innerHTML+="</table><head><center><br><font size=2>El imperio de la música ha llegado<br></head></html>";

}
function show(which,wind) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a><br>";
line += item[which][4] ;
wind.innerHTML+=line;

return 1;
}
// End -->
</script>

</font></font></font></font></font><form method="get" action="javascript:void(0)" onsubmit="search(this); return false;">


<center><font size="2"><font size="2"><font color=" #66666"><font size="2"><font color=" #66666"><input name="srchval" value="" size="20" type="text"><input value="BUSCAR" type="submit">
<div id="resultado"></div>
<br>

<!-- fin del buscador -->

Última edición por wwwja; 24/11/2009 a las 05:41
  #2 (permalink)  
Antiguo 23/11/2009, 15:39
 
Fecha de Ingreso: abril-2009
Mensajes: 51
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: sabrias hacer esto? [Buscador interno super sencillo][offline]

Encontré el codigo que quiero!!

pero no para firefox solo funciona en explorer y en Safari no prové

Código:
<script>
var NS4 = (document.layers);
var IE4 = (document.all);

var win = window; // Con frames usar top.nombre.window;
var n = 0;

function findInPage(str) {

var txt, i, found;

if (str == "")
return false;

// Find next occurance of the given string on the page, wrap around to the
// start of the page if necessary.

if (NS4) {

// Look for match starting at the current point. If not found, rewind
// back to the first match.

if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;

// If not found in either direction, give message.

if (n == 0)
alert("Not found.");
}

if (IE4) {
txt = win.document.body.createTextRange();

// Find the nth match from the top of the page.

for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}

// If found, mark it and scroll it into view.

if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}

// Otherwise, start over at the top of the page and find first match.

else {
if (n > 0) {
n = 0;
findInPage(str);
}

// Not found anywhere, give message.

else
alert("Not found.");
}
}

return false;
}

</script>

<form name="search" onSubmit="return findInPage(this.string.value);">
<font size="2"><p>Busca palabras</font><font size="3"><input name="string" type="text" size="15"
onChange="n = 0;"></font> <input type="submit" value="Buscar"></p>
</form>
</center>
  #3 (permalink)  
Antiguo 24/11/2009, 05:42
 
Fecha de Ingreso: abril-2009
Mensajes: 51
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Buscapalabras sabrias hacer esto? [Buscador interno super sencillo][offlin

He actualizado Si alquien puede, que me ayude!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:25.