Questa dovrebbe essere un copia funzionante.
Sono risalito all'elemento del DOM (il tag "a") partendo dalla selezione.
Ho commentato il codice.
codice:<html> <body bgcolor="#BEF781" vlink="#0000FF"> <center>Digitare le prime tre lettere:</center><br> <script> function searchForText(toFind, frameToSearch) { if (!toFind) { window.alert('You have not entered any text to search for'); return } if (frameToSearch.focus) { frameToSearch.focus() } if (window.find) { if (document.layers) { var ifFound = frameToSearch.find(toFind, !1, !1) } else { var ifFound = frameToSearch.find(toFind, !1, !1, !0, !1, !0, !1) } //recupero la selezione range=window.getSelection().getRangeAt(0); //dalla selezione risalgo al nodo (<a>) che la contiene e redirigo verso l'url location.href=range.commonAncestorContainer.parentNode.href; } else if (frameToSearch.document.body && frameToSearch.document.body.createTextRange) { if (frameToSearch.document.selection && frameToSearch.document.selection.type != 'None') { var theRange = frameToSearch.document.selection.createRange(); theRange.collapse(!1) } else { var theRange = frameToSearch.document.body.createTextRange() } var ifFound = theRange.findText(toFind); if (ifFound) { theRange.select(); range=window.getSelection().getRangeAt(0); location.href=range.commonAncestorContainer.parentNode.href; } } else { alert('Please use your browser\'s search facility') } if (!ifFound) { alert('Could not find text:\n' + toFind) } }; </script> <div align=center> <script> if ((document.body && document.body.createTextRange) || window.find) { document.write('<form action="" onkeyup="if ( this.elements[0].value.length >2 ){searchForText( this.elements[0].value, window );}">' + '<input style="text-align:center" id="tre" autofocus="autofocus" type="text" onclick="this.value=null" maxlength="3" size="3"> </form>'); } if (!("autofocus" in document.createElement("input"))) { document.getElementById("tre").focus(); } </script> </div> <center><br><br> <a href="http://google.com" class="text">GOOGLE</a><br><br> <a href="http://youtube.com" class="text">YOUTUBE</a><br><br> <a href="http://facebook.com" class="text">FACEBOOK</a><br><br> <a href="http://twitter.com" class="text">TWITTER</a><br><br> <a href="http://eccetera.com" class="text">ecc. ecc....</a><br><br> </center> </body> </html>

Rispondi quotando