I want to display an image before uploading. I tried the following code, but it only works in firefox.but, I need to get it to work in IE. Can anyone suggest me a better solution for this. I give my code below can someone figure out where I went I googled almost one whole day. But could not find my solution. Here is my 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]); } } } }
My html
<body><form method="post" > <input type="file" class="file" onchange="loadname(this,'previewimg')" id="file" /><img src="about:blank" name="previewimg" id="previewimg" alt="" style="width:2in; height:2in"/> </form>
source share