Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: JavaScript
Expertise: Intermediate
Jun 1, 2005



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Use JavaScript to Scale an Image According to Window Size

Sometimes you need to resize an image according to the window's size. You can do this by setting the image width and height as 100 percent inside the <img> tag. IE then resizes the image according to the window's size.

You can also do this with JavaScript, using document.body.clientWidth and document.body.clientHeight. These return the active window width and height. On_Load sets the image width and height. When the window is resized, width.history.go(0) refreshes the page.

<script language="javascript">
function ScaleSize()
document.getElementById("imgTag").style.width = document.body.clientWidth;
document.getElementById("imgTag").style.height = document.body.clientHeight;
<body onload="javascript:ScaleSize();" onresize="history.go(0)">
<img id="imgTag" src="c:\Test.jpg"  />   
Santhi Maadhaven
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date