Does the 'body' tag have an onblur tag?

I tried to associate the onblur event with the <body> , and it works in IE 6/8.

However, when I switch to w3schools , it turns out that the <body> does not have an onblur event.

Can anyone explain this?

+4
source share
3 answers

The HTML4 specification does not contain an onblur attribute.

HTML5 project , on the other hand.

+3
source

body:onblur is part of the HTML5 specification, but is not part of the HTML4 specification.

If you want to support the HTML4 browser, why not use window:onblur ? In most cases, you will have the same functionality.

+2
source

I would never rely on the source you mentioned. The problem is that MSIE fires a blur event for almost every element, <body on. Most other implementations are made by the exact oposite.

This may help if you explicitly specified a tabIndex for the body element , for example:

 document.body.tabIndex = 1; document.body.onblur = function() { alert('body blur'); }; 

This works for me on FF5. However, I'm not sure how many versions from FF and how many implementations support this β€œcomplicated” workaround.

The next logical question: why do you need to fire the body blur event? The only reasonable thing I can think of is that you want to know when someone leaves your page? If so, I would recommend looking at the window itself, not the body.

 window.onblur = function() { alert('window blur'); } 
0
source

All Articles