[POO] Pourquoi ca marche pas ? onLoad & onUnload...
Bonjour, j'aimerais juste une explication.
Je travaille sous Mozilla (car sinon tout fonctionne sous IE)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript">
function init_formulaire(obj)
{
//obj.onunload = function (){ alert("ok"); }
document.getElementsByTagName('body')[0].onunload = function (){ alert("ok"); }
}
</script>
</head>
<body onload="init_formulaire(this)">
</body>
</html> |
La ligne : document.getElementsByTagName('body')[0].onunload .....etc
ne fonctionne pas. Si on la met en commentaires et que l'on décommente :
obj.onunload = function (){....
Alors la tout marche.
Je ne comprend pas pourquoi.
Si quelqu'un a une explication, merci