0

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.

Community
  • 1
  • 1
peterrandon
  • 39
  • 1
  • 11

3 Answers3

1

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

Wayne Ellery
  • 7,888
  • 1
  • 28
  • 45
0

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

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • was looking for something more towards checking for if the tab was visible or not, sorry if that was not clear in the question – peterrandon Jun 28 '14 at 02:19
0

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

Example:

document.title = 'Alert';