gpt4 book ai didi

javascript - 从聊天框在 <title></title> 中创建新消息通知

转载 作者:行者123 更新时间:2023-11-28 09:40:19 26 4
gpt4 key购买 nike

我正在尝试为 my chat box 创建通知,当有人向您发送新消息时,会在“谈话”标题旁边看到。我尝试过多种方法,但从来没有成功过。

a busy cat http://goawaymom.com/damit.png

这是我的代码

$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){
var clientmsg = $("#usermsg").val();
$.post("post.php", {text: clientmsg});
$("#usermsg").attr("value", "");
return false;
});

//Load the file containing the chat log
function loadLog(){
$.ajax({
url: "log.html",
cache: false,
success: function(html){
var chatbox= $("#chatbox");
var atBottom = (chatbox[0].scrollHeight - chatbox.scrollTop() == chatbox.outerHeight());
chatbox.html(html);

if (atBottom )
chatbox.animate({ scrollTop: 99999 }, 'normal');
}
});
}
setInterval (loadLog, 2500); //Reload file every 2.5 seconds

//If user wants to end session
$("#exit").click(function(){
var exit = confirm("Are you sure you want to end the session?");
if(exit==true){window.location = 'index.php?logout=true';}
});
});

有人知道我会怎么做吗?到目前为止我所尝试的一切都失败了。我试过使用不起作用的设置间隔函数。

最佳答案

那么,如果我理解正确的话,提交消息会将其附加到 log.html 的末尾?我认为这对你想做的事情不起作用。您需要有一个服务来跟踪新帖子,以便您可以检查更新,而不仅仅是重新加载 div 的innerHTML。

完成此操作后,您可以记录自聊天获得焦点以来已加载的新消息数量,并在每次聊天获得焦点时将其重置为 0。

您可以使用 document.title 更新标题。因此,每当您需要更新计数时,您都可以这样做

document.title = 'my normal title (' + newCount + ')';

简单地说,这不是您可以使用 JavaScript 解决的问题,您需要重新设计您的应用程序。

关于javascript - 从聊天框在 &lt;title&gt;&lt;/title&gt; 中创建新消息通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12500990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com