
March 8th, 2001, 10:21 AM
|
|
Member
|
|
Join Date: Sep 2000
Location: Chicago, USA
Posts: 73
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
The following code is not mine and I can't remember for the life of me where I got it but I need help modifying it. What it does is takes a keyword from a form and searches the text on the page the script resides on and highlites any matches.
I want to put the script in a frame at the top of the page and have it search the text in the main frame but I dont know how to modify it so that it will do this. Any help will be much appreciated.
[CODE]
<script language="JavaScript">
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
var n = 0;
function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0)
alert("Not found.");
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert("Not found.");
}
}
return false;
}
</script>
|