F
FunGuySF
I have some content in a scrollable iframe. I update this content every 5
seconds using setInterval(). After updating the contents, I force the
window to scroll to the bottom (scrollBy), where I've placed the most
current content. The window is scrollable, so the user can scroll to the
top (older content) and read it if they wish. The code does add new content
to the bottom and scroll to the bottom... here it is:
function refreshContent(newContent) {
var tr, td;
tbody = parent.frameContent.bodyContent;
// Add new content at the bottom
for (var i = 0; i < newContent.length; i++) {
tr = tbody.insertRow(tbody.rows.length);
td = tr.insertCell(tr.cells.length);
td = tr.insertCell(tr.cells.length);
}
// scroll to bottom of chat window
parent.frmChat.scrollBy(0,10000);
}
Here's the problem. If a user has scrolled to the top of the window to
read, when the Interval kicks off, they are shot down to the bottom of the
page again, and lose their place. Is there some way for me to check if the
user is reading the window (i.e., not scrolled to the bottom), and skip the
scrollBy? Something like:
// check window scrollPosition before adding new text
scrollPosition = ??????;
// Add new content at the bottom
[...]
// scroll to bottom of chat window, if it was at the bottom before I
added content
if ( scrollPosition == [BOTTOM] ) {
parent.frmChat.scrollBy(0,10000);
}
Any ideas?
Thanks!
Mike
seconds using setInterval(). After updating the contents, I force the
window to scroll to the bottom (scrollBy), where I've placed the most
current content. The window is scrollable, so the user can scroll to the
top (older content) and read it if they wish. The code does add new content
to the bottom and scroll to the bottom... here it is:
function refreshContent(newContent) {
var tr, td;
tbody = parent.frameContent.bodyContent;
// Add new content at the bottom
for (var i = 0; i < newContent.length; i++) {
tr = tbody.insertRow(tbody.rows.length);
td = tr.insertCell(tr.cells.length);
td = tr.insertCell(tr.cells.length);
}
// scroll to bottom of chat window
parent.frmChat.scrollBy(0,10000);
}
Here's the problem. If a user has scrolled to the top of the window to
read, when the Interval kicks off, they are shot down to the bottom of the
page again, and lose their place. Is there some way for me to check if the
user is reading the window (i.e., not scrolled to the bottom), and skip the
scrollBy? Something like:
// check window scrollPosition before adding new text
scrollPosition = ??????;
// Add new content at the bottom
[...]
// scroll to bottom of chat window, if it was at the bottom before I
added content
if ( scrollPosition == [BOTTOM] ) {
parent.frmChat.scrollBy(0,10000);
}
Any ideas?
Thanks!
Mike