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!
The focus event fires when an element has received focus. The opposite of focus is blur . This event is not cancelable and does not bubble.
Use the document. hasFocus() method to check if a window has focus, e.g. if (document. hasFocus()) {} . The method returns a boolean value indicating whether the document or any element in the document has focus.
The focus event fires when an element has received focus. The event does not bubble, but the related focusin event that follows does bubble. The opposite of focus is the blur event, which fires when the element has lost focus. The focus event is not cancelable.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With