Display preview of image before upload in IE9
<p>I want to display the image before uploading.I tried the following code but it is working only in firefox.but i need to make it work in IE.Could any one suggest me the best solution for this.i am giving my code below could any one figure out where i went
I googled nearly one whole day.But couldnt find my solution
Here is my code</p>

<pre><code>enter code here

function loadname(img, previewName) {
      var isIE = (navigator.appName == "Microsoft Internet Explorer");
      var path = img.value;
      var ext = path.substring(path.lastIndexOf('.') + 1).toLowerCase();
      if (ext == "gif" || ext == "jpeg" || ext == "jpg" || ext == "png") {
          if (isIE) {
              alert(path);
              $('#' + previewName).attr('src', path);
          } else {
              if (img.files[0]) {
                  var reader = new FileReader();
                  reader.onload = function (e) {
                      $('#' + previewName).attr('src', e.target.result);
                  }
                  reader.readAsDataURL(img.files[0]);
              } 
          }
      } 
  }  
</code></pre>

<p>My html is</p>

<pre><code> &lt;body&gt;&lt;form method="post" &gt; 
&lt;input type="file" class="file" onchange="loadname(this,'previewimg')" id="file" /&gt;&lt;img src="about:blank" name="previewimg" id="previewimg" alt="" style="width:2in; height:2in"/&gt; 


&lt;/form&gt;
</code></pre>
