manix Posted August 10, 2011 Share Posted August 10, 2011 I want to send an ajax request to refresh a certain line in my site every time the window is focused, and it's giving me a major headache because neither this function() { $(window).focus(function() { alert("Thanks for visiting!"); }; }); nor this $(window).focus( function() { alert("Thanks for visiting!"); }); alert anything :@ Quote Link to comment https://forums.phpfreaks.com/topic/244393-jquery-headache/ Share on other sites More sharing options...
trq Posted August 10, 2011 Share Posted August 10, 2011 focus only applies to elements. You cannot apply it to the entire window object. Quote Link to comment https://forums.phpfreaks.com/topic/244393-jquery-headache/#findComment-1255201 Share on other sites More sharing options...
manix Posted August 10, 2011 Author Share Posted August 10, 2011 actually I can, the problem was, as always the dumbest crap, I forgot to include the jquery file... and the code if someone needs it is as follows: var returning = 0; $(window).focus( function() { if(returning==1) { alert("Thanks for visiting!"); returning = 0; } }); $(window).blur( function() { returning = 1; }); Quote Link to comment https://forums.phpfreaks.com/topic/244393-jquery-headache/#findComment-1255203 Share on other sites More sharing options...
.josh Posted August 10, 2011 Share Posted August 10, 2011 seems buggy in FF5.0 + jQuery v1.6.2 I have that on a test page and have it in one tab, and another tab to some other random place, and when I keep clicking back and forth between the two tabs, I seem to be only getting the alert every other focus. Quote Link to comment https://forums.phpfreaks.com/topic/244393-jquery-headache/#findComment-1255371 Share on other sites More sharing options...
trq Posted August 10, 2011 Share Posted August 10, 2011 It should be buggy, from the manual: This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property. Quote Link to comment https://forums.phpfreaks.com/topic/244393-jquery-headache/#findComment-1255610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.