Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launch Find from command button

Status
Not open for further replies.

sweetleaf

Programmer
Jan 16, 2001
439
CA
Hi,

Does anyone know how to launch the windows find utility from an HTML command button. I just don't want the user to have to press ctrl + F everytime they want to seearch for something on a web page..

Thanks,
Mark

 
You can probably automate the pop-up of the find window in IE, but I am not sure exactly how to do that. You could also use this find function.


<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var NS4 = (document.layers);
var IE4 = (document.all);
var win = this;
var n = 0;
function findInPage(str) {
var txt, i, found;
if (str == &quot;&quot;)
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + &quot; was not found on this page.&quot;);
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart(&quot;character&quot;, 1);
txt.moveEnd(&quot;textedit&quot;);
}
if (found) {
txt.moveStart(&quot;character&quot;, -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + &quot; was not found on this page.&quot;);
}
}
return false;
}
// End -->
</script>


------------------------------------------
Put this in the body

<form name=search onSubmit=&quot;return findInPage(this.string.value);&quot;>
<b><font face = &quot;Arial, Helvetica, sans-serif&quot;>Find on Page</b></font>
<input name=string type=text size=15 onChange=&quot;n = 0;&quot;>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top