javascript - Polling New Message Alert/Notification -
i developing web app makes constant ajax calls (polls) php pull new 'tasks' database, sort of how gmail/facebook checks new email , messages. current javascript code looks this:
dopoll(); function dopoll(){ $.post('ajax/tasks.php').done(function(data){ /* append tasks html dom */ }).always(function(){ settimeout(dopoll, 5000); }); } see example:jquery, simple polling example
i have gotten work well, problem alert user have new 'task' if in different tab. know facebook , google changing tab heading 'facebook' 'facebook(2)' indicating 2 new messages. seems norm, i've seen other websites yahoo, trello, etc. sufficient need , wondering if knew how this, notify when user in different tab. can guarantee user use app in chrome, tool chrome supports fine.
i change title. if wanted check if tab visible can use html5 page visibility. https://developer.mozilla.org/en-us/docs/web/guide/user_experience/using_the_page_visibility_api
Comments
Post a Comment