peterrandon
peterrandon

Reputation: 49

Polling New Message Alert/Notification

I am currently developing a web app that makes constant ajax calls (polls) to php to pull new 'tasks' from the database, sort of like how gmail/facebook checks for new email and messages. The current javascript code looks something like this:

doPoll();

function doPoll(){
   $.post('ajax/tasks.php').done(function(data){ 
      /* Append Tasks to HTML DOM */ 
   }).always(function(){
      setTimeout(doPoll, 5000); 
   });
}

see example:jQuery, simple polling example

I have gotten this to work well, my only problem now is that I would like to alert the user that they have a new 'task' if they are in a different tab. I know facebook and google do this by changing the Tab Heading from 'Facebook' to Something Like 'Facebook(2)' indicating 2 new messages. This seems like the norm, as I've seen other websites do this yahoo, trello, etc. This is sufficient for what I need to do and I was wondering if anyone knew how to do this, specifically only notify when the user is in a different tab. I can guarantee that the user will only use the app in Chrome, so any tool that Chrome supports will be fine.

Upvotes: 1

Views: 1163

Answers (3)

Alphapixels
Alphapixels

Reputation: 15

Just change the title dinamycally using JS, that's pretty much enough.

Example:

document.title = 'Alert';

Upvotes: 0

Wayne Ellery
Wayne Ellery

Reputation: 7958

I would just always change the title. If you really wanted to check if the tab is visible you can use html5 page visibility. https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API

Upvotes: 1

jcaron
jcaron

Reputation: 17710

Isn't just a matter of changing the document.title?

Upvotes: 0

Related Questions