Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > BODY onBlur event?

Reply
Thread Tools

BODY onBlur event?

 
 
D. Alvarado
Guest
Posts: n/a
 
      10-24-2004
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-24-2004


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/
 
Reply With Quote
 
 
 
 
DU
Guest
Posts: n/a
 
      10-25-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<body onBlur="self.close()"> liu Javascript 2 07-21-2007 02:10 PM
To reduce your body weight & slim your body Loss weight MCSA 0 07-21-2007 05:15 AM
Body onblur="window.close()" =?Utf-8?B?bGluZGFucg==?= ASP .Net 5 04-24-2006 07:04 PM
Problem with <body onBlur="window.close()"> Peter Page Javascript 0 04-01-2005 08:22 PM
Cannot get onBlur to work in body tag if a text input is focused jeff@dnuk.com Javascript 0 11-19-2003 10:11 PM



Advertisments