简体   繁体   中英

IE 11 not rendering div on javascript properly

I am using IE 11 , and it fails to render div dialog properly. All the dimensions viz. height, width, top, left give inappropriate results. The same is working fine for IE10.

The javascript code snippet is as follows:-

if (height > 0 && width > 0)
{
    myDialog.height = height;
    myDialog.width = width;
    myDialog.top = (parseInt(document.body.clientHeight) - height) / 3;
    myDialog.left = (parseInt(document.body.clientWidth) - width) / 2;
}  

Here, myDialog is the div object I am talking about. why is this code snippet failing for IE11. Any help is appreciated.

You're setting properties on the HTMLDivElement instance. You may have more success setting them on its style property:

if (height > 0 && width > 0)
{
    myDialog.style.height = height + "px";
    myDialog.style.width = width + "px";
    myDialog.style.top = ((parseInt(document.body.clientHeight) - height) / 3)  + "px";
    myDialog.style.left = ((parseInt(document.body.clientWidth) - width) / 2)  + "px";
}  

Note I've also added px to the end, since these are CSS-style measurements.

try following

if (height > 0 && width > 0)

{

myDialog.style.height = height;
myDialog.style.width = width;
myDialog.style.top = (parseInt(document.body.clientHeight) - height) / 3;
myDialog.style.left = (parseInt(document.body.clientWidth) - width) / 2;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM