Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
How to scroll selected text to the top of window?
Old 08-13-2004, 06:35 AM How to scroll selected text to the top of window?
Junior Talker

Posts: 3
Trades: 0
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.
Vukas is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to How to scroll selected text to the top of window?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48100 seconds with 12 queries