Pessoal, estou com um problema que sei que não é difícil de se resolver
Preciso fazer um sisteminha que localize as palavras dentro de 1 página do site, ou seja a página que estiver em execução.
Mais ou menos como aquele comando do windows Ctrl+F de localizar.
Se alguem souber por favor socorra-me, é urgente.
Um abraço
Publicidade
|
|
Page 1 of 1
Não me lembro como se faz - ctrl+f Busca dentro da página
#2
Posted 29 March 2005 - 05:42 PM
Olha esse Java Script:
<html>
<head>
<script Language="JavaScript">
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ão foi encontrada nesta página.");
}
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ão foi encontrada nesta página.");
}
}
return false;
}
</script>
</head>
<body>
<form name=search onSubmit="return findInPage(this.string.value);">
Lacalizar palavra na página:
<input name=string type=text size=30 onChange="n = 0;">
<input type=submit value="Localizar">
</form>
</body>
</html>
Ele localiza e destaca a palavra que vc digitou no formulário
CODE
<html>
<head>
<script Language="JavaScript">
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ão foi encontrada nesta página.");
}
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ão foi encontrada nesta página.");
}
}
return false;
}
</script>
</head>
<body>
<form name=search onSubmit="return findInPage(this.string.value);">
Lacalizar palavra na página:
<input name=string type=text size=30 onChange="n = 0;">
<input type=submit value="Localizar">
</form>
</body>
</html>
Share this topic:
Page 1 of 1
Similar Topics
| Topic | Forum | Started By | Stats | Last Post Info | |
|---|---|---|---|---|---|
|
Duvida site sem ser frame
como montar algo parecido |
Dúvidas Gerais |
Gisa Iagami
|
|
|
|
RSF teme que China bloqueie todo site estrangeiro que não aceite autocensura
|
Notícias |
Notícias
|
|
|
|
Menu espacial 3d
Alguém tem como me ajudar a fazer isso? |
Flash & ActionScript |
VernonLacerda
|
|
|
|
Teste mostra como o iPad "americano" funciona no Brasil; veja
|
Notícias |
Notícias
|
|
|
|
Efeito de nuvens voando
como fazer????????? |
Flash & ActionScript |
oinuj
|
|
|
|
Erramos: Sandra Bullock, Tiger Woods e Kim Kardashian lideram buscas no Bing em 2010
|
Notícias |
Notícias
|
|
|
|
como fazer isso... - Menu
ajudinha, se possivel... |
Fireworks |
klein
|
|
|
|
FComboBox.additem
Como usar item de xml e valor? |
Flash & ActionScript |
verdijr
|
|
Publicidade
|
|

Help













