user760912
user760912

Reputation: 59

IE9 and IE8 loading image set a width

var img_src="/xxx.jpg";
var img = new Image();
img.src = img_src;
 //img.height=height;
 img.width=200;
 img.removeAttribute('height');

The Image is loading with default size in IE8 and IE9 and i have checked it in google chrome and firefox it is working fine.

Upvotes: 0

Views: 542

Answers (2)

Neil
Neil

Reputation: 55402

I suspect IE overwrites the width and height attributes when the image loads. To work around the problem, use img.style.width = "200px"; img.style.height = "auto";.

Upvotes: 1

Igor Dymov
Igor Dymov

Reputation: 16460

Width or Height have to be set with units like:

img.width = "200px";

Upvotes: 1

Related Questions