if you just scrollheight it will make a problem when user will want to see his previous message. so you need to make something that when new message come only then the code. use jquery latest version. 1.here I checked the height before message loaded. 2. again check the new height. 3. if the height is different only that time it will scroll otherwise it will not scroll. 4. not in the if condition you can put any ringtone or any other feature that you need. that will play when new message will come. thanks
var oldscrollHeight = $("#messages").prop("scrollHeight");
$.get('msg_show.php', function(data) {
div.html(data);
var newscrollHeight = $("#messages").prop("scrollHeight"); //Scroll height after the request
if (newscrollHeight > oldscrollHeight) {
$("#messages").animate({
scrollTop: newscrollHeight
}, 'normal'); //Autoscroll to bottom of div
}