BODY onBlur event?

D

D. Alvarado

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
 
M

Martin Honnen

D. Alvarado said:
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);">
 
D

DU

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top