user3041657
user3041657

Reputation: 1

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.

Upvotes: 0

Views: 1613

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074385

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.

Upvotes: 1

Indranil.Bharambe
Indranil.Bharambe

Reputation: 1498

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;
}

Upvotes: 0

Related Questions