Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/01/2008, 14:21
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 8 meses
Puntos: 834
Re: Buscar texto en una página

A ver si te sirve este ejemplo:
Frameset:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>ejemplo</title>
</
head>

<
frameset rows="170,*" cols="*" framespacing="0" frameborder="no" border="0">
  <
frame src="buscador.php" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
  <
frame src="formbus.php" name="mainFrame" id="mainFrame" title="mainFrame" />
</
frameset>
<
noframes><body>
</
body>
</
noframes></html
topFrame (en ejemplo, nombre buscador.php):
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BUSCADOR</title>
<script>
String.prototype.preg_quote=function(){
	p= /([:.\+*?[^\]$(){}=!<>|:)])/g;
	return this.replace(p,"\\$1");
}
function buscar(cadena){
	resetear();
    if(!cadena.length)return;
	var info3;
	cadena=cadena.preg_quote();
	var patron=new RegExp(cadena+'(?!\}\})','gim');
	var espacio=/^\s$/;
	var el=document.getElementsByTagName('html')[0].getElementsByTagName('*');
	for(var i=0;i<el.length;i++){
		if(el[i].hasChildNodes){
			var tt=el[i].childNodes;
			for(var jj in tt){
				if(tt[jj].nodeType==3 && !espacio.test(tt[jj].nodeValue)){
					patron.lastIndex = 0;
					if(info3=patron.exec(tt[jj].nodeValue)){
						tt[jj].nodeValue=tt[jj].nodeValue.replace(patron,'{{'+tt[jj].nodeValue.substr(info3['index'],cadena.length)+'}}');
				
					}
				}

			}		
		}
	}
	document.getElementsByTagName('body')[0].innerHTML=document.getElementsByTagName('body')[0].innerHTML.split('}}').join('</span>').split('{{').join('<span style="background-color: #FFFF99">');
}
function resetear(){
	original=document.getElementsByTagName('body')[0].innerHTML=original;
}
window.onload=function(){
	original=document.getElementsByTagName('body')[0].innerHTML;
}
</script>
</head>

<body>
ver Buscador simple
<div>sí, dije buscador <div id="pepe">buscador <span> y
      metemos otra vez la palabra buscador} a ver /a qué pasa</span><span>algo
      más </span>y
      esto fuera del span y dentro de div </div>
</div> 
y si ponemos buscador fuera otra vez?
</body>
</html>
mainFrame (en ejemplo, archivo formbus.php):
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Untitled Document</title>
</
head>

<
body>
<
form id="form1" name="form1" method="post" action="">
  <
input name="cadena" type="text" id="cadena" />
  <
input type="button" name="Button" value="buscar" onclick="parent['topFrame'].buscar(cadena.value)" />
</
form>
</
body>
</
html

Última edición por Panino5001; 07/01/2008 a las 10:49