Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  171] [ 4]  / answers: 1 / hits: 19169  / 14 Years ago, mon, january 10, 2011, 12:00:00

Google Reader has a nice feature that when you switch to the web page from a different web page (giving the page focus) it will show you the updates there were accumulated while the page was unfocused.

Quick question #1: How do they do that?



I figure that they might be binding to the mouse move events + keyboard events since I don't know any out of the box event that gives you that ability.



Googling for that is a nightmare (focus, tab, web page, user).



Quick question #2: Is there some package out there that gives me that ability?



I'm putting the jQuery tag as a beacon for all the web developers ninjas out there, but I don't really care about the framework (as long as its Javascript)


More From » html

 Answers
9

Try using jQuery's focus and blur functions:





$(window).focus(function() {
console.log('welcome (back)');
});

$(window).blur(function() {
console.log('bye bye');
});

<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
Click in and out of this frame to test the focus and blur functions.




[#94291] Sunday, January 9, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shekinah

Total Points: 699
Total Questions: 112
Total Answers: 110

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;