Detectar Blur / Focus a la ventana

30/Ene/2015 192

Este pequeño snippet permite detectar y realizar alguna acción mediante JavaScript cuando una ventana/tab esté activa (focus) ó desactiva (blur).

Algunas aplicaciones útiles que se me ocurren:

  • Guardar datos si el usuario está en un formulario.
  • Iniciar/detener animaciones que quieras que el usuario vea.

A pesar de actualmente existir una API para Page Visibility sabemos que su soporte para IE es escaso. En este caso se utilizarán los eventos onfocus y onblur los que tienen buen soporte (IE8+).

function windowBlurFocus(){
  var focused = true;
  window.onfocus = function() {
    focused = true;
    onFocus();
  };
  window.onblur = function() {
    focused = false;
    onBlur();
  };
}

Ver Ejemplo

Comentarios

  1. Znfwdx [#]

    free slots – online casino slots no download free slots online

  2. KevinWet [#]

    gay dating tips how to find
    helpfulonly gay dating
    best gay casual dating sights

  3. Gfnfkl [#]

    best ed pill – ed medications online pills for erectile dysfunction

  4. Nneyyf [#]

    ed treatment review – medications that cause erectile dysfunction best otc ed pills

  5. Numfjw [#]

    prednisone over the counter – where can you buy prednisone without a prescription prednisone 30 mg daily

  6. Ngnqlf [#]

    prednisone 2018 – prednisone 60mg no prescription prednisone 1 mg price

  7. KevinWet [#]

    good free gay dating site
    gay kink dating
    gay dating tips

  8. Ovljwl [#]

    buy viagra no prescription – viagra generic 50 mg cost of 100mg viagra

  9. Pqmkmq [#]

    buy sildenafil in canada – sildenafil rx drugstore online viagra tablet 25 mg price in india

  10. bahis siteleri [#]

    Turkiyede faaliyet gosteren saglayan en guvenilir bahis siteleri

  11. Gilberto [#]

    I appreciate, result in I discovered exactly what I used to be
    having a look for. You’ve ended my 4 day lengthy
    hunt! God Bless you man. Have a nice day. Bye

  12. PatrickFax [#]

    cialis coupon buy cialis usa

  13. web hosting but [#]

    Heya i’m for the first time here. I came across this board and I find It
    truly useful & it helped me out much. I hope to give something back
    and aid others like you helped me.

  14. it web hosting [#]

    Every weekend i used to visit this website, for the reason that i wish for enjoyment, as this this website
    conations really nice funny material too.

  15. web hosting what [#]

    This design is steller! You obviously know how to keep a
    reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  16. PatrickFax [#]

    cialis 20mg cialis dosage

  17. http://t.co [#]

    Hi, all is going fine here and ofcourse every one is
    sharing information, that’s truly fine, keep
    up writing.

  18. bit.ly [#]

    Very nice post. I just stumbled upon your weblog and wished to say that I’ve really enjoyed surfing around
    your blog posts. After all I’ll be subscribing to your rss feed and I hope you write again very soon!

  19. t.co [#]

    You need to take part in a contest for one of the greatest sites on the web.
    I’m going to recommend this blog!

  20. hydroxychloroquineMt [#]

    biden hydroxychloroquine how to get hydroxychloroquine hydroxycloro

  21. ivermectin [#]

    ivermectin na prodej Detectar Blur / Focus a la ventana | CSSLab | Laboratorio de ideas web http://ivermectin1.com/ ivermectina oral

  22. hydroxychloroquineMt [#]

    how to make hydroxychloroquine buy chloroquin define hydrochloric

  23. hydroxychloroquineMt [#]

    hydroxychloroquine sulfate 200mg does hydroxychloroquine cause hair loss does hydroxychloroquine require a prescription

  24. HenryUnfiP [#]

    free casual gay dating sites
    brrt gay dating site
    free gay military dating sites

  25. bitly.com [#]

    Pretty! This was an extremely wonderful article.
    Many thanks for supplying these details. scoliosis surgery https://0401mm.tumblr.com/ scoliosis
    surgery

  26. j.mp [#]

    Hi to all, the contents present at this website
    are actually remarkable for people knowledge, well, keep up
    the good work fellows. cheap flights http://1704milesapart.tumblr.com/ cheap
    flights

  27. app.gumroad.com [#]

    Highly descriptive blog, I loved that bit. Will there be a
    part 2? asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

  28. quest bars there [#]

    I’m not sure why but this site is loading incredibly slow for me.
    Is anyone else having this problem or is it a issue on my end?
    I’ll check back later on and see if the problem still exists.
    quest bars http://tinyurl.com/49u8p8w7 quest bars

  29. http://bitly.com/ [#]

    I am sure this article has touched all the internet users, its really
    really nice article on building up new weblog. ps4 https://tinyurl.com/45xtc52b ps4 games

  30. Mobile recharge [#]

    What a beautiful blog

  31. http://www.iherb.com [#]

    Thank you a lot for sharing this with all people you actually realize what you’re speaking approximately!
    Bookmarked. Kindly additionally visit my site =). We may have
    a hyperlink exchange contract between us quest
    bars https://www.iherb.com/search?kw=quest%20bars quest bars

  32. http://coub.com [#]

    Greate pieces. Keep writing such kind of info on your page.
    Im really impressed by your blog.
    Hi there, You’ve done an excellent job. I will certainly
    digg it and in my opinion suggest to my friends. I am confident they will be benefited from this web site.
    scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

  33. cialis 20 mg [#]

    cialis 20mg cialis online

  34. HenryUnfiP [#]

    gay dating denver
    gay dating chat rooms
    gay dating sites kentucky

  35. pharmaceptica [#]

    hydroxychloroquine hcq https://www.pharmaceptica.com/

  36. provigilgeneric [#]

    buy provigil modafinil otc

  37. modafinilprice [#]

    modafinil moa modafinil alcohol

  38. bactrim coverage [#]

    trimoxazole side effects sulfameth trimethoprim

  39. pharmaceptica.com [#]

    chloroquine phosphate cvs https://www.pharmaceptica.com/

  40. provigilcost [#]

    provigil price what is modafinil used for

  41. buymodalert [#]

    what is modafinil used for buy provigil online

  42. modafinilhalflife [#]

    buy modafinil modalert reddit

CSSLab