Michele Basso
a- a+

Motore di Ricerca interno alla pagina

Con questo DHTML possiamo inserire un motore di ricercainterno alla pagina, che simula la funzioneModifica>Trova presente nel browser. Inpratica i risultati verranno evidenziati, uno alla volta, adogni pressione del tasto "trova" presente nel form.

Lo script, creato da Alan Koontz, ècompatibile con Internet Explorer 4 esuperiori, Netscape7, eMozilla, mentre non ècompatibile con Netscape 6.

Per utilizzare lo script, è sufficiente copiare questocodice all'interno del tag body nellapagina web in cui dobbiamo eseguire la ricerca:

<script><!-- Hide from old browsers/******************************************* Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com)* Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code* Modified Jan 4th, 03'. This notice must stay intact for use******************************************///  revised by Alan Koontz -- 9/18/02var TRange = null;var win = null;var frameval = false;//  SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT//  http://www.mozilla.org/docs/web-developer/sniffer/browser_type.htmlvar nom = navigator.appName.toLowerCase();var agt = navigator.userAgent.toLowerCase();var is_major  = parseInt(navigator.appVersion);var is_minor  = parseFloat(navigator.appVersion);var is_ie     = (agt.indexOf("msie") != -1);var is_ie4up  = (is_ie && (is_major >= 4));var is_nav    = (nom.indexOf('netscape')!=-1);var is_nav4   = (is_nav && (is_major == 4));var is_mac    = (agt.indexOf("mac")!=-1);var is_gecko  = (agt.indexOf('gecko') != -1);//  GECKO REVISIONvar is_rev=0if (is_gecko) {temp = agt.split("rv:")is_rev = parseFloat(temp[1])}//  USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH//  (SELF OR CHILD FRAME)//  If you want to search another frame, change "self" below to//  parent.frames["thisframe"]//  where "thisframe" is the name of the target frame//  eg: var frametosearch1 = parent.frames["thisframe"]var frametosearch1 = selffunction search(whichform, whichframe) {//  TEST FOR IE5 FOR MAC (NO DOCUMENTATION)if (is_ie4up && is_mac) return;//  TEST FOR NAV 6 (NO DOCUMENTATION)if (is_gecko && (is_rev <1)) return;//  INITIALIZATIONS FOR FIND-IN-PAGE SEARCHESif(whichform.findthis.value!=null && whichform.findthis.value!='') { str = whichform.findthis.value; if(whichframe!=self) frameval=true;  // this will enable Nav7 to search child frame win = whichframe;    }else return;  //  i.e., no search string was enteredvar strFound;//  NAVIGATOR 4 SPECIFIC CODEif(is_nav4 && (is_minor < 5)) {     strFound=win.find(str); // case insensitive, forward search by default//  There are 3 arguments available://  searchString: type string and it's the item to be searched//  caseSensitive: boolean -- is search case sensitive?//  backwards: boolean --should we also search backwards?//  strFound=win.find(str, false, false) is the explicit//  version of the above//  The Mac version of Nav4 has wrapAround, but//  cannot be specified in JS     }//  NAVIGATOR 7 SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)if (is_gecko && (is_rev >= 1)) { if(frameval!=false) win.focus(); // force search in specified child frame    strFound=win.find(str, false, false, true, false, frameval, false);//  There are 7 arguments available://  searchString: type string and it's the item to be searched//  caseSensitive: boolean -- is search case sensitive?//  backwards: boolean --should we also search backwards?//  wrapAround: boolean -- should we wrap the search?//  wholeWord: boolean: should we search only for whole words//  searchInFrames: boolean -- should we search in frames?//  showDialog: boolean -- should we show the Find Dialog?} if (is_ie4up) {  // EXPLORER-SPECIFIC CODE  if (TRange!=null) {    TRange.collapse(false)    strFound=TRange.findText(str)    if (strFound) TRange.select();   }  if (TRange==null || strFound==0) {    TRange=win.document.body.createTextRange()    strFound=TRange.findText(str)    if (strFound) TRange.select();  } }  if (!strFound) alert ("String '" +str+ "' not found!") // string not found  }// --></script><!--  EXAMPLE FORM OF FIND-IN-PAGE SEARCH USING SUBMIT (ALLOWING 'ENTER/RETURN' KEY PRESS EVENT) --><form name="form1" action="" onSubmit="search(document.form1, frametosearch1); return false"><input type="text" name="findthis" size="15" title="Press 'ALT s' after clicking submit to repeatedly search page"> <input type="submit" value="Find in Page" ACCESSKEY="s"></form></textarea></p><p>Per problemi nell'utilizzo dello script, potete consultare il nostro <a href="http://forum.webmasterpoint.net" target="_blank">forumdi discussione</a>.<br></p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>  <!--<div id="copyright"><a href="link" target="_blank">txt</a></div>-->    </div>    <!-- /articolo -->  <div id="tools">  <div class="sommario">[ <a href="home.asp">Sommario</a> ]</div>    <div><a href="javascript:open_window('../../int/stampa.asp',260,380)"><img alt="Stampa News" src="../../int/print.gif" />Stampa Pagina</a> - <a href="../../info/autore.asp?nome=Michele+Basso"><img src=/img/guide/83/autore.gif" alt="Info sull'autore" />Info sull'autore</a></div>    <div>SEGNALA QUESTA LEZIONE AD UN AMICO CON <a href="javascript:open_window('../../send_icq.asp?page=https://www.webmasterpoint.org/appunti/dhtml/36.asp',430,350)"><img alt="ICQ" src="../../int/icq.gif" />ICQ</a> o <a href="javascript:open_window('../../send_pag.asp?page=https://www.webmasterpoint.org/appunti/dhtml/36.asp',430,350)"><img alt="EMAIL" src="../../int/email.gif" />EMAIL</a></div>    <div><a href="http://forum.webmasterpoint.net" target="_blank"><img alt="forum" src="../../int/forum.gif" />DISCUTI DI QUESTA LEZIONE SUL FORUM</a></div>    </div>    </div></div><hr /><div id="colonnadx"> <center><a href="http://ads.webmasterpoint.org/adclick/http://domain.mvmnet.com/" target="_blank" title="[SPONSOR] eDomain (Link Esterno)"><img class="banner" src=/img/guide/83/edomain_120.gif" alt="[SPONSOR] eDomain (Link Esterno)" /></a>  <br />    <a href="http://ads.webmasterpoint.org/adclick/http://www.rubalo.it/" target="_blank" title="[SPONSOR] Rubalo (Link Esterno)"><img class="banner" src="/sponsor/rubalo.gif" alt="[SPONSOR] Rubalo (Link Esterno)" /></a>    <br />    <a href="http://ads.webmasterpoint.org/adclick/http://www.consultingweb.it" target="_blank" title="[SPONSOR] ConsultingWeb (Link Esterno)"><img class="banner" src="/sponsor/consultingweb_120.gif" alt="[SPONSOR] ConsultingWeb (Link Esterno)" /></a>   <br /><br /><div class="ml">    <h2 class="ml">Newsletter</h2>    <p>Iscriviti alla nostra newsletter per ricevere novita e aggiornamenti dal nostro sito in modo GRATUITO!</p>     <form name="newsletter" action="/reg_nl.asp" method="post"><div><input type="text" class="email" name="email" value="la tua email" onfocus="value=''"/></div>  <ul>    <li><input type="checkbox" name="asp" id="asp_newsletter" value="si" checked/><label for="asp_newsletter">ASP</label></li>  <li><input type="checkbox" name="flash" id="flash_newsletter" value="si" checked/><label for="flash_newsletter">Flash</label></li>  <li><input type="checkbox" name="frontpage" id="frontpage_newsletter" value="si" checked/><label for="frontpage_newsletter">Front Page</label></li>  <li><input type="checkbox" name="webmarketing" id="webmarketing_newsletter" value="si" checked/><label for="webmarketing_newsletter">Web Marketing</label></li>  <li><input type="checkbox" name="webmaster" id="webmaster_newsletter" value="si" checked/><label for="webmaster_newsletter">Aggiornamenti</label></li>  </ul> <div class="right"><input type="submit" class="iscriviti" name="iscriviti" value="iscriviti" /></div>    </form></div>    <br /><br /><script language="JavaScript"> var code = '';var now = new Date();var nIndex = now.getTime();document.write('<s' + 'cript src=/img/guide/83/area.asp?id_a=9&tamp=' + nIndex + '">');document.write('</' + 's' + 'cript>');</script><script language="JavaScript">document.write(code);</script><script language="JavaScript"> var code = '';var now = new Date();var nIndex = now.getTime();document.write('<s' + 'cript src=/img/guide/83/area_ads.asp?id_a=1&tamp=' + nIndex + '">');document.write('</' + 's' + 'cript>');</script><script language="JavaScript">document.write(code);</script></center>    </div></div><!-- /CONTENUTI --><hr /><!-- FOOTER --><div id="footer">    <div>2000-2010 WebMasterPoint.org -  <a href="https://www.webmasterpoint.org/info/notelegali.asp" title="[INFORMAZIONI] Informazioni legali su WebMasterPoint">  Note Legali</a> -  <a href="https://www.webmasterpoint.org/info/privacy.asp" title="[INFORMAZIONI] Rispettiamo la vostra privacy">  Privacy</a> -  <a href="https://www.webmasterpoint.org/info/pubblicita.asp" title="[INFORMAZIONI] Per informazioni sulla pubblicita su WebMasterPoint">  Pubblicità</a><br>  Tutti i contenuti di Webmasterpoint.org sono pubblicati secondo la licenza di utilizzo di   <a target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/2.0/">Creative Commons</a>, salvo diverse indicazioni. <br>  Gestione tecnica di  <a href="mailto:lorenzo.pascucci@webmasterpoint.org" title="[INFORMAZIONI] Per errori sul sito, problemi tecnici sul sito o consigli contattare Lorenzo Pascucci">  Lorenzo Pascucci</a> - Web-Marketing di  <a href="mailto:marcello.tansini@webmasterpoint.org" title="[INFORMAZIONI] Per informazioni pubblicitarie contattare Marcello Tansini">  Marcello Tansini</a>    </div></div><!-- /FOOTER --><script language="JavaScript"> var code = '';var now = new Date();var nIndex = now.getTime();document.write('<s' + 'cript src=/img/guide/83/area.asp?id_a=175&timestamp=' + nIndex + '">');document.write('</' + 's' + 'cript>');</script><script language="JavaScript">document.write(code);</script></body><script type="text/javascript" language="JavaScript" src=/img/guide/83/script><script type="text/javascript" language="JavaScript" src=/img/guide/83/script></html>

Per problemi nell'utilizzo dello script, poteteconsultare il nostro forum didiscussione.



Ti potrebbe interessare anche

commenta la notizia