www.webdeveloper.com
Results 1 to 3 of 3

Thread: How detect a tab getting focus?

  1. #1
    Join Date
    Sep 2010
    Posts
    2

    How detect a tab getting focus?

    How can I do something like "browserTab.onfocus = myFunction" by which I mean that "myFunction" would get control any time something in it's browser tab gains focus? E.g., when the user switches from a different browser tab or a non-browser window. I don't need to know what got focus, just that something did in that tab.

    "window.onfocus = myFunction" with event capturing works fine except when the main window contains frames. Doing document.getElementById('iframeId').contentWindow.addEventListener('focus',myFunction,true) to add an onfocus handler to the iframe's document works in Firefox except when the frame's content comes from another site, which is my case and I cannot modify that site. I'd rather not poll using document.hasFocus().

    Ideas? Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by DougL View Post
    except when the frame's content comes from another site, which is my case and I cannot modify that site.
    Then you can do nothing. By default, there is no possibility to gain JavaScript control over a document from another domain, for obvious security reasons.

  3. #3
    Join Date
    Sep 2010
    Posts
    2
    I only want to know if something in the tab gets focus. I don't really care to get control of another domain.

    - Doug

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles