Rechercher un mot dans une page

Télécharger ici le code source du script ( 671 Octets )

Testez en tapant l'un des mots ci-dessous :

gendarme  police  garde municipal java militaire ........................

    Copiez et collez ce script avant la balise </body> :

<script language="JavaScript">
var n = 0;
function findInPage(str) {
 var txt, i, found;
 if (str == "") return false;
 if (document.layers) {
  if (!window.find(str)) while(window.find(str, false, true)) n++;
  else n++;
  if (n == 0)
  alert("Not found.");
  }
 if (document.all) {
  txt = window.document.body.createTextRange();
  for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
   txt.moveStart("character", 1);
   txt.moveEnd("textedit");
   }
 if (found) {
  txt.moveStart("character", -1);
  txt.findText(str);
  txt.select();
  txt.scrollIntoView();
  n++;
  }
 else {
  if (n > 0) {
   n = 0;
   findInPage(str);
   }
  else
   alert("Not found.");
   }
  }
 return false;
 }
</script>
<form name="search" onSubmit="return findInPage(this.string.value);">
<font size=3><input name="string" type="text" size=15 onChange="n = 0;"></font>
<input type="submit" value="chercher">
</form>

© Copyright GendNet 2000 Tout droit de reproduction strictement réservé aux membres de l'association ®