3

Hey, i just noticed something on facebook.com, facebook was in my other tab, and i was browsing on SO, after a while i switched back to facebook.com and it like fades in new news in the wall. How did they make a script that knows when you are active again without clicking anywhere it shall refresh new messages etc. ? Just like facebook chat also if you have it on another tab/window then you'll hear "blub" or Facebook: **NEW MESSAGE FROM: name. How does it do that?

Do it run a timeout checker each second, i dont think so ? , that would be really alot of traffic and server response time, if around 3-4-500 million users would do that each day.

Could someone provide example where to place ajax call if it the user has left the focus and its getting onfocus again, how to make a code that runs a ajax call there? jquery?

Karem
  • 17,615
  • 72
  • 178
  • 278
  • 2
    maybe it watches for mouse events on the `` – Pointy Aug 28 '10 at 16:20
  • 1
    http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active – Anurag Aug 28 '10 at 16:29
  • Anurag i do not understand the link quitly. Could someone provide example where to place ajax call if it the user has left the focus and its getting onfocus again, how to make a code that runs a ajax call there? jquery? – Karem Aug 28 '10 at 16:33
  • the tricky bit is figuring out when a user returns to a page. Anurag provided a clear example. I think you have enough to go from there rather than asking him to do all the work for you. I'm saying this to be constructive and not to sound mean. – donohoe Aug 28 '10 at 17:54

1 Answers1

1

Would this not work using the focus event on the window object? ie:

window.onfocus = refreshStuff;

where refreshStuff is your function for refreshing...err...stuff.

https://developer.mozilla.org/en/DOM/window
http://msdn.microsoft.com/en-us/library/ms536934(v=VS.85).aspx

Sorry - I would have added this to the comments, but I can't - possibly because I don't have enough reputation yet.

ndtreviv
  • 3,473
  • 1
  • 31
  • 45