eewald
08-07-2003, 10:19 AM
When I load a window.. I want something to happen later if the window is in focus. Is there a way to detect if the window is infocus? A property maybe? I bet this is easy.. argh.
|
Click to See Complete Forum and Search --> : focus property eewald 08-07-2003, 10:19 AM When I load a window.. I want something to happen later if the window is in focus. Is there a way to detect if the window is infocus? A property maybe? I bet this is easy.. argh. pyro 08-07-2003, 10:21 AM Yep, a simple event handler: <script type="text/javascript"> function myFunction() { alert ("Window is in focus."); } window.onfocus = myFunction; </script> eewald 08-07-2003, 10:27 AM Right now when I load a page I wait for an event to fire. Then I create the event handler for on and off focus like you suggested which works perfectly. The problem is .. that I want the focus event to fire if the window is currently in focus when I set the event handler. Thanks for the quick reply! pyro 08-07-2003, 10:30 AM This should work -- give it a try, and let me know... :) add this to the end of your script: window.onload = window.focus(); eewald 08-07-2003, 10:50 AM Heres my code(as general as I could make it :p) function EventListener(id, arg) { if(id==4) { window.onfocus = dostuff; window.onblur = dootherstuff; function dostuff() { _______ //cool actions } function dootherstuff() { _______ // other cool actions } } } So nothing happens onfocus or onblur before event 4 happens. And the cool actions happen after event 4 happens. But I need the cool actions to happen when the event is fired based on whether the current window is in focus. I got a "not implemented" error when I tried window.onload=window.focus(); Did i need to change the name? pyro 08-07-2003, 11:00 AM Sorry, my bad, window.onload = window.focus; should be: window.onload = function () { window.focus(); } eewald 08-07-2003, 11:07 AM That didnt seem to do anything. So that would make the onload function the focus function.. which would trigger the focus function when the window is loaded? But in this case the window is already loaded so it fired the dummy focus event well before event 4 fired .. right? webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |