Mozilla/Firefox text scroll fix.

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/63557?pagenum=1
05 November 2025, 03:13

Topic


Eric Coleman
Mozilla/Firefox text scroll fix.
15 December 2006, 11:30


This really isn't a full mod, but I didn't know where else to post this.
The bug is when using the javascript formating options, such as bold, italics, etc, in a textbox with enough lines of text to have scroll bars, the textbox scrolls all the way to the top.

This easy fix keeps the scroll bar where it is when click the formating buttons.

Open inc_code.js and find the following function AddText
Code needs to be placed at the beginning of the function and at the end of the function:

Paste the following
Code:

	var crtScrollTop;
var crtScrollLeft;
try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
crtScrollTop = tarea.scrollTop;
crtScrollLeft = tarea.scrollLeft;
}
} catch (e) {};

at the top, immediatly after function AddText(text) {

Then, at the bottom of the function, paste the following:
Code:

	;
try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
tarea.scrollTop = crtScrollTop;
tarea.scrollLeft = crtScrollLeft;
}
} catch (e) {};

immediately BEFORE the closing } of the function.

That's it.

If you haven't made any changes to your javascript then the default function, as being used by this forum right now, would look like this where new code is blue and old code is red.
Code:

function AddText(text) {
	var crtScrollTop;
var crtScrollLeft;
try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
crtScrollTop = tarea.scrollTop;
crtScrollLeft = tarea.scrollLeft;
}
} catch (e) {};
var tarea = document.PostTopic.Message;
if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
start = tarea.selectionStart;
end = tarea.selectionEnd;
tarea.value = tarea.value.substr(0,tarea.selectionStart)
+ text + tarea.value.substr(tarea.selectionEnd);
tarea.focus();
tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
tarea.selectionEnd = start + text.length;
} else {
if (tarea.createTextRange && tarea.caretPos) {
var caretPos = tarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else {
tarea.value += text;
}
tarea.focus(caretPos);
}
;

try {
var tarea = document.PostTopic.Message;
if (typeof tarea.scrollTop != 'undefined') {
tarea.scrollTop = crtScrollTop;
tarea.scrollLeft = crtScrollLeft;
}
} catch (e) {};
}
<

 

Replies ...


HuwR
15 December 2006, 11:46


nice one, I guess it should be included in a future release at some point.<
Shaggy
17 April 2008, 12:11


Ah-ha! Knew I'd seen this somewhere smile
But, of course, the byte-scrimping coder in me had to clean it up a bit wink
Code:
function AddText(text) {
var tarea = document.PostTopic.Message;
if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
start = tarea.selectionStart;
end = tarea.selectionEnd;
var posTop = tarea.scrollTop;
var posLeft = tarea.scrollLeft;
tarea.value = tarea.value.substr(0,tarea.selectionStart)
+ text + tarea.value.substr(tarea.selectionEnd);
tarea.focus();
tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
tarea.selectionEnd = start + text.length;
tarea.scrollTop = posTop;
tarea.scrollLeft = posLeft;
} else if (tarea.createTextRange && tarea.caretPos) {
var caretPos = tarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
tarea.focus(caretPos);
} else {
tarea.value += text;
}
}
<
© 2000-2021 Snitz™ Communications