My previous chat script worked perfect at sender side. When ever a new message is added from textbox to databinder the scroll bar used to come down with the help of javascript but the issue is it is unable to scroll down the recipient's side chat script. I interfaced scroll down code to button using OnClientClick
. So, on each button click scroll bar used to come down but how can I able to scroll down recipient's scroll bar too when I click on enter?
Asked
Active
Viewed 582 times
1

Mal
- 533
- 1
- 12
- 27
-
click on enter? You mean you use the enter key? What is it focused on? – epascarello Sep 22 '11 at 17:52
-
1@epascarello - I believe that the question is clear. Hope you must read it again. – Mal Sep 22 '11 at 17:55
-
Nope it is not clear, hence why I asked. – epascarello Sep 22 '11 at 19:14
-
I asked how to scroll down the **recipient's scroll bar** when I add a new chat text at *sender side.* – Mal Sep 22 '11 at 19:20
-
I understand that, How does enter come into play? That is all I wanted to know. – epascarello Sep 22 '11 at 22:44
1 Answers
1
So I believe you are having issues with the recipient of a chat message. After the new message is added to the list of messages, the content holder doesn't scroll down to the new message. I'm guessing you are using a textarea or a div to hold the content.
I found two other questions on StackOverflow with good answers:
var objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;
StackOverflow: Scroll to bottom of div?
function moveCursorToEnd(input)
{
var lastPosition = input.value.length - 1;
if (input.setSelectionRange)
{
input.focus();
input.setSelectionRange(lastPosition, lastPosition);
}
else if (input.createTextRange)
{
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', lastPosition);
range.moveStart('character', lastPosition);
range.select();
}
}
Tested Firefox 6 and IE8: http://jsfiddle.net/nXa4d/
StackOverflow: With help from: jQuery Set Cursor Position in Text Area

Community
- 1
- 1

Darren Griffith
- 3,290
- 3
- 28
- 35