document.createElement + IE
Posté : 08 sept. 2008, 16:24
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
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);