Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/08/2012, 23:10
cerd0
 
Fecha de Ingreso: agosto-2008
Mensajes: 48
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: Juntar 2 scripts en una funcion Onclick, EN un Buscador Interno html

Tengo otro codigo de buscador que si hace esa funcion, de ir a la palabra de busqueda automaticamente, pero en su defecto no me resalta la palabra buscada. ya intente de varias formas hacer que trabajen juntos, o de unir ambos codigos, pero no puedo, por favor alguien puede hecharme una mano?

Ya intente separar las funciones en el evento con punto y coma ; para que se ejecuten ambas, pero no logro hacerlo de otras formas ya no se que mas intentar.

Este ES EL BUSCADOR que va a la palabra buscada automatico


Código Javascript:
Ver original
  1. </script>
  2.  
  3.  
  4. <script language="JavaScript">
  5. <!-- More javascripts http://www.hypergurl.com -->
  6.  
  7. var NS4 = (document.layers);    // Which browser?
  8. var IE4 = (document.all);
  9.  
  10. var win = window;    // window to search.
  11. var n   = 0;
  12.  
  13. function findInPage(str) {
  14.  
  15.   var txt, i, found;
  16.  
  17.   if (str == "")
  18.     return false;
  19.  
  20.   // Find next occurance of the given string on the page, wrap around to the
  21.   // start of the page if necessary.
  22.  
  23.   if (NS4) {
  24.  
  25.     // Look for match starting at the current point. If not found, rewind
  26.     // back to the first match.
  27.  
  28.     if (!win.find(str))
  29.       while(win.find(str, false, true))
  30.         n++;
  31.     else
  32.       n++;
  33.  
  34.     // If not found in either direction, give message.
  35.  
  36.     if (n == 0)
  37.       alert("Not found.");
  38.   }
  39.  
  40.   if (IE4) {
  41.     txt = win.document.body.createTextRange();
  42.  
  43.     // Find the nth match from the top of the page.
  44.  
  45.     for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
  46.       txt.moveStart("character", 1);
  47.       txt.moveEnd("textedit");
  48.     }
  49.  
  50.     // If found, mark it and scroll it into view.
  51.  
  52.     if (found) {
  53.       txt.moveStart("character", -1);
  54.       txt.findText(str);
  55.       txt.select();
  56.       txt.scrollIntoView();
  57.       n++;
  58.     }
  59.  
  60.     // Otherwise, start over at the top of the page and find first match.
  61.  
  62.     else {
  63.       if (n > 0) {
  64.         n = 0;
  65.         findInPage(str);
  66.       }
  67.  
  68.       // Not found anywhere, give message.
  69.  
  70.       else
  71.         alert("Not found.");
  72.     }
  73.   }
  74.  
  75.   return false;
  76. }
  77.  
  78. </script>
  79.  
  80.  
  81.  
  82.  
  83. <body bgcolor="#FFFFFF" text="#000000">
  84. <p>
  85.  
  86.  
  87. <form name="search" onSubmit="return findInPage(this.string.value);">
  88. <input name="string" id="buscador" type="text" size=15 onChange="n = 0;">
  89.  <input type="submit" value="Search Page"></form>


Muchas gracias