8

I am wondering if it is possible to get a event when the user switches back to "your" page's window? This could happen either when the user opens a new tab and then switches back to your page's tab or when the user closes safari and then opens it again.

I want to be able to update content on the page once I get this event. I am using a setInterval to accomplish this now, but it would be nice to not have the delay when the user focuses on your window.

Thanks!

joneath
  • 81
  • 1
  • 3
  • Now this question was raised exactly two years ago to the date. Does anyone know if there are still no such events? – mzedeler Oct 01 '12 at 13:46

2 Answers2

1

I've been digging around and found that a focus event is fired when the window is activated again.

It should be doable like this (using jQuery):

$(window).on('focus', function() {
    ...focus code here...
});

This event is probably fired more often than needed, but it worked for me.

mzedeler
  • 4,177
  • 4
  • 28
  • 41
1

The chance of this one getting resolved seems small:

I created this script to log as many WebKit events as possible (event names taken from http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/dom/EventNames.h), and it doesn't seem to trigger any event upon leaving/bringing to front Safari.

Jacob Oscarson
  • 6,363
  • 1
  • 36
  • 46