I’m trying to create notifications for my chat box, as seen beside the ‘talk’ title when ever some one new messages you. I’ve tried multiple things that never work.
a busy cat http://goawaymom.com/damit.png
here is my code
$(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';}
});
});
does any body know how i would go about this. Everything I’ve tried so far has failed. I tried
using a set interval function that didn’t work.
So, if I’m understanding correctly, submitting a message will append it to the end of log.html? I don’t think that’s going to work for what you’re trying to do. You need to have a service to keep track of new posts so that you can check for updates, rather than just reloading the innerHTML of a div.
Once you have that in place, you can keep a count of how many new messages you’ve loaded since the chat had focus and reset it to 0 every time the chat gets focus.
You can update the title using document.title. So whenever you need to update the count, you can do
Simply put, this isn’t a problem you can solve with javascript, you need to redesign your app.