SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to add onfocus event to body in javascript for Mozilla Browser

    function funBodyFocus()
    {
    //My Code...
    }
    document.body.addEventListener('onfocus', funBodyFocus, false);

    For mozilla browser,
    here i m adding onfocus EventListener to body in javascript.
    but its not working.
    Plz help me on this...

    Regards
    Adil

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    The body has only the onload and onunload events.

  3. #3
    SitePoint Evangelist asprookie's Avatar
    Join Date
    May 2005
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't focus on the whole body. It defeats the purpose, that's why it doesn't exist .

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adilsyed View Post
    function funBodyFocus()
    {
    //My Code...
    }
    document.body.addEventListener('onfocus', funBodyFocus, false);
    For mozilla browser,
    here i m adding onfocus EventListener to body in javascript.
    but its not working.
    Plz help me on this...
    Regards
    Adil
    BTW, what is the purpose of adding new onFocus event on body? When you browse a page from the URL then automatically the Body will get focused. may we know that for what purpose you want to add onFocus event?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Evangelist asprookie's Avatar
    Join Date
    May 2005
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you browse a page from the URL then automatically the Body will get focused.
    Rajug got it right

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to do this for several reasons. Gmail does this somehow when you have a chat window open and focus the tab/window again. They then change your status to available.

  7. #7
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's mostly about keyboard navigation.

    When the window has focus the tab order may begin at the address bar or in a sidebar of the browser.
    If you open the page with no anchor, calling document.body.focus() onload will start the tab order on the first focusable element on the page itself.

    You can call document.body.focus() to remove the focus from another element that has the focus.
    This has the effect of passing subsequent key events directly to the body. It also resets tab key navigation, sending the user back to the beginning of the page, which can be a problem. It is often best to focus on some element of the body, rather than the body itself.


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
  •