如何使shoutbox聊天日志滚动到底部并不断刷新而不改变鼠标焦点?
我正在编写一个小型的Shoutbox/聊天应用程序,其中使用以下代码每 0.5 秒刷新一次消息日志 div 并刷新到底部以显示最新消息。
$(setInterval(function() {
$('.messageLog').load('display_messages.php');
window.location='#bottom';
}, 500));
'#bottom' 指的是我放在 '.messageLog' div 末尾的空 div,因此我有一个位置可以称为消息日志的底部。此方法的问题是,当我尝试登录时(只需输入用户名并通过聊天框顶部的小表单按下登录按钮),用户名输入字段不断刷新并失去焦点在 Firefox 和 Internet Explorer 中每 0.5 秒一次(在 Chrome 中工作正常)。问题原来是“window.location='#bottom'”行,它导致了输入字段聚焦问题。
我想知道是否有办法解决这个问题,以便我仍然可以每 0.5 秒刷新一次消息日志并自动滚动到底部,同时不会干扰用户尝试通过用户名字段登录。
I am writing a small shoutbox/chat app where I am using the following piece of code to refresh the message log div every 0.5 seconds and to refresh to the bottom to show the latest message.
$(setInterval(function() {
$('.messageLog').load('display_messages.php');
window.location='#bottom';
}, 500));
the '#bottom' refers to a empty div I have put at the end of the '.messageLog' div so I have a location to refer to as the bottom of the message log. The problem with this method is, when I am trying to login (by simply typing in a username and pressing the sign-in button through a small form at the top of the chatbox) the username input field keeps getting refreshed and put out of focus every 0.5 seconds in firefox and internet explorer (works fine in chrome). The problem turns out to be the line "window.location='#bottom'", which is causing the input field focusing problem.
I was wondering if there was a way around this so that I can still refresh the message log every 0.5 seconds and automatically scroll to the bottom while not interfere with users trying to sign in through the username field.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除锚点,用它代替
remove the anchor, use this instead