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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for Words in One Page Only

Status
Not open for further replies.

dance

Technical User
Nov 6, 2002
142
0
0
US
I am using FrontPage 2002. I want to search for words in one page only. I know I can add a Search Component that searches for words throughout the web and returns the PAGE where the word is found. But I need for the visitor to put in a word to find on a single page the way you can in Microsoft Word. Is this a possibility? Maybe with HTML code? I know you can have bookmarks, but that is not the same as searching.
 
Here's some javascript that's equivalent to the Find command that searches the current page.

<script language=&quot;JavaScript&quot;>
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
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(&quot;Not found.&quot;);
}
if (IE4) {
txt = win.document.body.createTextRange();
// Find the nth match from the top of the page.
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(&quot;Not found.&quot;);
}
}
return false;
}
</script>
</head>

<body>

<p>Search on just this page.</p>
<form name=&quot;search&quot; onSubmit=&quot;return findInPage(this.string.value);&quot;>
<font size=3><input name=&quot;string&quot; type=&quot;text&quot; size=15 onChange=&quot;n = 0;&quot;></font><input type=&quot;submit&quot; value=&quot;Find&quot;></form>

</body>
</html>

Is that what you wanted, or did you want to do a search on just one page, but not the page you are on?

If so, Front Page lets you search by directory. Put your special page in its own directory. Right click on your search.htm page and choose &quot;Search Form Properties&quot; and &quot;Search results&quot;. In the directory text box, type in the folder that you want to limit your search to.
Paul
 
Paul,
Thanks for the code. But I don't know what to do with it. I copied it to the html page, but it doesn't do anything. The source code on this page had changed all the &quot;s to &quot. I tried changing those to &quot;. It had also added many &nbsp's, but I assume those are o.k. Also, when I viewed it in Preview mode, there was a message, &quot;Runtime error in line 12. Syntax error&quot;.
I inserted the code between <head> and </head>. I know HTML, but nothing of Java.
If you can give me any more help I'll appreciate it.
Sandra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top