|
Hello, I have two imputs in my form: text and button. Pressing the button javascript searches and selects appropriate text string in the same document. Selected text string appears near bottom or top side of the window according where this string was found - below or above of visible area of the document.
I need this selection to be always shown near top side of the window (not bottom). I tried to add scrollIntoView(true) method, but I failed. There is my code:
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();
// Find the nth match from the top of the page.
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();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert("Not found!");
}
}
return false;
}
Could you help me to modify this code to reach my goals stated above?
Thank you a lot!
Vukas.
|