BODY onBlur event?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D. Alvarado

    BODY onBlur event?

    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="savePag e();">

    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
  • Martin Honnen

    #2
    Re: BODY onBlur event?



    D. Alvarado wrote:
    [color=blue]
    > 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="savePag e();">
    >
    > 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.[/color]

    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('sav ePage();', 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="clearTi meout(tid);">

    --

    Martin Honnen

    Comment

    • DU

      #3
      Re: BODY onBlur event?

      D. Alvarado wrote:

      [color=blue]
      > Ideally, what I want to happen is that when someone leaves window A,
      > window A executes a command.[/color]

      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 :)

      Comment

      Working...