Foros del Web » Programando para Internet » Javascript »

Buscador interno

Estas en el tema de Buscador interno en el foro de Javascript en Foros del Web. Por favor si alguien me puede decir como hacer un buscador interno, desde ya gracias...
  #1 (permalink)  
Antiguo 07/05/2002, 12:22
 
Fecha de Ingreso: mayo-2002
Mensajes: 6
Antigüedad: 22 años
Puntos: 0
Buscador interno

Por favor si alguien me puede decir como hacer un buscador interno, desde ya gracias
  #2 (permalink)  
Antiguo 07/05/2002, 14:26
Avatar de ferny
Il capo della mafia
 
Fecha de Ingreso: febrero-2002
Ubicación: Al final del cable
Mensajes: 10.080
Antigüedad: 22 años, 2 meses
Puntos: 55
Re: Buscador interno

Visita <a href='ir.asp?http://www.freefind.com' target='_blank'>http://www.freefind.com...</a>, es muy bueno. También se puede hacer con javascript, lo que hace es buscar palabras en la página donde esté este código:
Código:
&lt;!-- Copiar dentro del tag BODY --&gt;

&lt;script language=&quot;JavaScript&quot;&gt;

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 == &quot;&quot;)
    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(&quot;Not found.&quot;);
  }

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

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

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

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

    if (found) {
      txt.moveStart(&quot;character&quot;, -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 &gt; 0) {
        n = 0;
        findInPage(str);
      }

      // Not found anywhere, give message.

      else
        alert(&quot;Not found.&quot;);
    }
  }

  return false;
}

&lt;/script&gt;

&lt;form name=&quot;search&quot; onSubmit=&quot;return findInPage(this.string.value);&quot;&gt;
  &lt;font size=&quot;2&quot;&gt;&lt;p&gt;&lt;/font&gt;&lt;font size=&quot;3&quot;&gt;&lt;input name=&quot;string&quot; type=&quot;text&quot; size=&quot;15&quot;
  onChange=&quot;n = 0;&quot;&gt;&lt;/font&gt; &lt;input type=&quot;submit&quot; value=&quot;Buscar&quot;&gt; &lt;/p&gt;
&lt;/form&gt;
Saludos


<hr>
"En teoría no hay diferencia entre teoría y práctica, pero en la práctica sí la hay"
Mira <a href="http://club.telepolis.com/dvd_a_video_avi/index.htm">http://club.telepolis.com/dvd_a_video_avi/index.htm</a>
  #3 (permalink)  
Antiguo 07/05/2002, 15:05
 
Fecha de Ingreso: enero-2002
Mensajes: 74
Antigüedad: 22 años, 4 meses
Puntos: 0
Re: Buscador interno

otro ejemplo
&lt;script language=&quot;JavaScript&quot;&gt;
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 == &quot;&quot;)
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0)
alert(&quot;Not found.&quot;);
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i &lt;= n &amp;&amp; (found = txt.findText(str)) != false; i++) {
txt.moveStart(&quot;character&quot;, 1);
txt.moveEnd(&quot;textedit&quot;);
}
if (found) {
txt.moveStart(&quot;character&quot;, -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n &gt; 0) {
n = 0;
findInPage(str);
}
else
alert(&quot;Not found.&quot;);
}
}
return false;
}
&lt;/script&gt;
&lt;form name=&quot;search&quot; onSubmit=&quot;return findInPage(this.string.value);&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;p&gt;&lt;/font&gt;&lt;font size=&quot;3&quot;&gt;&lt;input name=&quot;string&quot; type=&quot;text&quot; size=&quot;15&quot;
onChange=&quot;n = 0;&quot;&gt;&lt;/font&gt; &lt;input type=&quot;submit&quot; value=&quot;Buscar&quot;&gt; &lt;/p&gt;&lt;/form&gt;&lt;p align=&quot;center&quot;&gt;&lt;b&gt;&lt;font size=&quot;2&quot; face=&quot;Arial&quot;&gt;Las palabras que podes elegir
para probar el buscador de palabras puede ser cualquiera de estas. Tan solo tienes que escribirlo en el cuadro de texto y presionar el boton BUSCAR.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;&lt;p
  #4 (permalink)  
Antiguo 07/05/2002, 19:50
 
Fecha de Ingreso: febrero-2002
Mensajes: 681
Antigüedad: 22 años, 2 meses
Puntos: 0
Re: Buscador interno

Si vas a usar un servicio, FreeFind.com es la mejor eleccion, fijate en mi site, abajo a l a derecha hay una caja de busqueda, funciona muy bien

<html><center><embed src="http://conozcasupc.tripod.com.ar/Banerr.swf" height=60 width=468>
</embed></center></html>
  #5 (permalink)  
Antiguo 26/06/2003, 14:54
 
Fecha de Ingreso: enero-2003
Ubicación: La Plata. Buenos Aires.
Mensajes: 9
Antigüedad: 21 años, 3 meses
Puntos: 0
El código de ferny está muy bueno y lo he utilizado en uno de mis sitios. Pero quiero hacer un aporte.
La línea:
for (i = 0; i <= n & (found = txt.findText(str)) != false; i++)

se debe reemplazar por:
for (i = 0; i < n & (found = txt.findText(str)) != false; i++)

para que la búsqueda no saltee el primer match.

Gracias. Y prometo empezar a aportar información a este sitio.
  #6 (permalink)  
Antiguo 26/06/2003, 15:01
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Estupendo

Bienvenido a los foros, sr_Vinagre

Un saludo
  #7 (permalink)  
Antiguo 06/02/2004, 11:57
 
Fecha de Ingreso: febrero-2002
Ubicación: Navarra
Mensajes: 701
Antigüedad: 22 años, 3 meses
Puntos: 2
Como podria adaptar el buscador que a puesto ferny, para que me busque dentro de un iframe???

Un saludo
__________________
asp, php, .net, adaptandose a las necesidades
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 01:10.