SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,307
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    cross browser page active or not detection?

    i'm interested in knowing when the page is active and when it's not (another browser window, or tab, or different app, is in front). i found this code:

    Code:
    if (/*@cc_on!@*/false) { // check for Internet Explorer
            document.onfocusin = onFocus;
            document.onfocusout = onBlur;
    } else {
            window.onfocus = onFocus;
            window.onblur = onBlur;
    }
    in both my browsers this works only partly and in different ways.

    in an old mac safari blur happens when the app is changed away from the browser (and focus when changed back), and when a new browser window is made active (and focus when original window made active again), but doesn't work with tabs; don't get blur when a new tab is created and accessed or an already existing one is accessed (nor focus when switching tabs back to original tab).

    in a mac firefox it works with tabs and different windows, but on app switch no blur event but there is a focus event when making browser app (with original window in front) active again.

    presumably there's going to be all manor of anomilies with other browsers. any one know of some already existing code which attempts to cope with these differences and get round some of them?

    or, a couple of more specific questions: how to get safari to report tab changes, and how to get firefox to report the app losing focus?

    thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,307
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    no thoughts on this?

    what about firefox? (version i'm talking about happens to be v2 on the mac but the problem may be on more recent ones i'm not sure). how to get it to acknowledge losing focus when the browser is no longer the app in the foreground? (it acknowledges focus when browser put back into the foreground.) or is there just no way to do that?

    thanks.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    onfocus and onblur are not standard events for windows and so only some browsers support them - with more supporting onfocus than support onblur.

    When a tab or window does lose the focus then you are not going to have any JavaScript run in that tab or window until it gets the focus back and so testing for it losing the focus from within JavaScript isn't all that useful even where it is supported - you'd need to do the test from the window that actually gets the focus.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,307
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    oh right, ok, thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •