You are here: irt.org | FAQ | JavaScript | Misc | Q283 [ previous next ]
In Netscape Navigator 4 you can combine the documents find() method with the documents getSelection() method to create a simple page search facility. The Copy button copies any selected/highlighted text into the form. The Find button then attempts to find any ocurrences of the text in the form in the page.
<script language="JavaScript1.2"><!--
if (document.layers) {
document.write('<form name="myform">');
document.write('<input type="text" name="mytext">');
document.write(' <input type="button" name="getstring" value="Copy" onClick="document.myform.mytext.value = document.getSelection()">');
document.write(' <input type="button" value="Find" onClick="find(document.myform.mytext.value,false)">');
document.write('<\/form>');
}
//--></script>