HighDots Forums  

Figuring out where user is scrolled in an iframe

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Figuring out where user is scrolled in an iframe in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
FunGuySF
 
Posts: n/a

Default Figuring out where user is scrolled in an iframe - 01-16-2005 , 07:45 PM






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



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.