Home » CodeDigest


Fit Popup window Size to the Image Size using JavaScript in ASP.Net
Submitted By Satheesh Babu B
On 1/2/2009 6:41:07 AM
Tags: CodeDigest,JavaScript  

Fit Popup window Size to the Image Size using JavaScript


There may be requirements where we need to display the full image in a popup window when we click a thumbnail image in aspx page. By default, the popup window will display the full image with lots of white spaces on the sides of the window. To make the image to exactly fit the popup window, we need to set the popup dimension to the image dimension.


The following code snippet will help us to fit the popup window dimension to the image dimension using JavaScript. 


    <script language="javascript">

    function FitImageToWindow()


    var width = document.images[0].width;

    var height = document.images[0].height;   






    <img src="new.jpg" onload="FitImageToWindow()" />   



In the above code, the popup window is resized using window.resizeTo() method by specifying the image width and height as the popup window's dimension through the javascript method FitImageToWindow(). This javascript method will be called on onload event of the event.



Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..