BODY onBlur event?

Discussion in 'Javascript' started by D. Alvarado, Oct 24, 2004.

  1. D. Alvarado

    D. Alvarado Guest

    Hi, I'm having some trouble with the "onBlur" event in the BODY tag.
    Ideally, what I want to happen is that when someone leaves window A,
    window A executes a command. I had put

    <body onBlur="savePage();">

    I have a couple of problems. On IE 6 (win2000), whenever I put the
    cursor focus on a textfield within window A, the "savePage" function
    is invoked. And on Mozilla Filefox 0.9.1, the event never launches
    even when I leave the window.

    Does anyone know how I can solve these respective problems?

    Thanks in advance, - Dvae
    D. Alvarado, Oct 24, 2004
    #1
    1. Advertising

  2. D. Alvarado wrote:

    > I'm having some trouble with the "onBlur" event in the BODY tag.
    > Ideally, what I want to happen is that when someone leaves window A,
    > window A executes a command. I had put
    >
    > <body onBlur="savePage();">
    >
    > I have a couple of problems. On IE 6 (win2000), whenever I put the
    > cursor focus on a textfield within window A, the "savePage" function
    > is invoked. And on Mozilla Filefox 0.9.1, the event never launches
    > even when I leave the window.


    For Mozilla you might want to use
    window.onblur = function (evt) {
    savePage();
    }
    that should work with IE too but of course the original problem is not
    solved by that, namely that exactly one object can have the focus
    meaning when you focus on some object in the window the window looses
    focus and thus the onblur handler is called. One way to try to work
    around that is to have
    var tid;
    window.onblur = function (evt) {
    tid = setTimeout('savePage();', 20);
    }
    and then to make sure that every element in the page that can get the
    focus cancels the timeout e.g.
    <input type="text" onfous="clearTimeout(tid);">

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 24, 2004
    #2
    1. Advertising

  3. D. Alvarado

    DU Guest

    D. Alvarado wrote:


    > Ideally, what I want to happen is that when someone leaves window A,
    > window A executes a command.


    Then coding the body onblur is definitively not best. Depending on what
    is your webpage context, design requirements, etc., coding/resorting to
    onbeforeunload event (which is supported by NS 7.2, Mozilla 1.6+, MSIE
    6) might be what you need. Here, we don't even know if window A is a
    script-initiated window or a non-script initiated window nor which type
    of command.

    DU
    --
    The site said to use Internet Explorer 5 or better... so I switched to
    Mozilla 1.7.3 :)
    DU, Oct 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bGluZGFucg==?=

    Body onblur="window.close()"

    =?Utf-8?B?bGluZGFucg==?=, Apr 11, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    7,150
    =?Utf-8?B?bGluZGFucg==?=
    Apr 24, 2006
  2. John Kotuby

    Does the onblur event still work in IE7?

    John Kotuby, Jun 24, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    448
    Munna
    Jun 24, 2008
  3. Replies:
    0
    Views:
    88
  4. Peter Page

    Problem with <body onBlur="window.close()">

    Peter Page, Apr 1, 2005, in forum: Javascript
    Replies:
    0
    Views:
    83
    Peter Page
    Apr 1, 2005
  5. liu

    <body onBlur="self.close()">

    liu, Jul 21, 2007, in forum: Javascript
    Replies:
    2
    Views:
    230
Loading...

Share This Page