My previous cha开发者_运维技巧t 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?
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
精彩评论