Rechercher un texte dans page

        Ce script permet de lancer une recherche de texte dans la page très simplement à l'aide d'un petit champ de formulaire.

Trouver

 Téléchargez ici le script ( 840 Octets )

    1 - Copiez avant entre les balises <head> et </head> où bon vous semble :

<script language="JavaScript">

<!-- Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + " n\'a pas été trouvé dans cette page.");
}
if (IE4) {
txt = win.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(str + " n\'a pas été trouvé dans cette page.");
}
}
return false;
}
// End -->
</script>

    2 - Copiez avant entre les balises <body> et </body> où bon vous semble :

<form name="search" onsubmit="return findInPage(this.string.value);">
<font size="2" face="Arial">Trouver <input name="string" type="text" size="15" onchange="n = 0;"> </font>
</form>

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