Page 1 sur 1

document.createElement + IE

Posté : 08 sept. 2008, 16:24
par zecreator
Bonjour,

Je rencontre un problème de création avec ce code sous IE. Sous Firefox et Chrome, ça fonctionne bien entendu.

Mon nouvel élément ne s'affiche pas, ou partiellement sous IE.

Merci de votre aide.
Zecreator

Code : Tout sélectionner

// Récupère les dimension de la page var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } // Supprime l'élément s'il existe déjà avant de le recréer if(document.getElementById('msg_box_frame') != undefined){ document.body.removeChild(document.getElementById('msg_box_frame')); } var msg_box_frame2 = document.createElement('div'); // Centre le calque sur la page xpos = Math.round((myWidth - 400)/2); ypos = Math.round((myHeight - 300)/2); msg_box_frame2.setAttribute('id','msg_box_frame'); msg_box_frame2.setAttribute('style','position: absolute; background-color: #EEEEEE; border-style: solid; border-width: 1px; border-color: #CCCCCC; width: 400px; height: 300px; left: ' + xpos + 'px; top: ' + ypos + 'px; visibility: visible; z-index: 50;'); msg_box_frame2.innerHTML = '<table border="0" width="100%"><tr><td style="text-align: center; font-weight: bold;" width="100%">Titre</td></tr>'; msg_box_frame2.innerHTML = msg_box_frame2.innerHTML + '<tr><td style="text-align: right;" width="100%">Message</td></tr></table>'; document.body.appendChild(msg_box_frame2);

Posté : 08 sept. 2008, 17:10
par _activmik
Essaye getElementbyObject pour IE à la place de getElementById

Posté : 08 sept. 2008, 21:32
par Victor BRITO
Normalement, createElement et getElementById sont implémentés sans problème sous IE (quoique, pour getElementById, IE cherche aussi du côté de l'attribut name, anomalie corrigée pour IE 8, du moins c'est ce qui est annoncé).