If you would like to set the maximum width for an image on a webpage, you can use the “max-width” attribute of style(CSS). But this attribute is supported by FireFox and some other browsers but not Internet Explorer (IE). The following code snippet shows you how to achieve the same thing as “max-width” for Internet Explorer using javascript.
ASP.NET
<asp:Image runat=”server” ID=”Image1″ ImageUrl=”test.jpg” style=”max-width:150px;”/>
HTML
<img id=”Image1″ src=”test.jpg” style=”max-width:150px;” />
JavaScript Code
var Img = document.getElementById(‘<%=Image1.ClientID %>’);
//use document.getElementById(‘Image1′); for HTML
if (Img.width > 150) {
Img.style.width = 150;
}





very cool & good js tip, thank you very much for sharing.
By: JavaScript Media Player on July 25, 2010
at 8:43 am
The problem with resizing images is that it takes time to load big images, thus the resetting of the width does not render properly.
By: Peter Bulloch on August 19, 2010
at 3:17 pm